diff --git a/quickshell/Common/I18n.qml b/quickshell/Common/I18n.qml index 147ea4512..a6371b19c 100644 --- a/quickshell/Common/I18n.qml +++ b/quickshell/Common/I18n.qml @@ -189,6 +189,26 @@ Singleton { } } + readonly property var _termIndexes: new WeakMap() + + function _termIndex(table) { + const cached = _termIndexes.get(table); + if (cached) + return cached; + const index = {}; + for (const c in table) { + const bucket = table[c]; + if (!bucket) + continue; + for (const term in bucket) { + if (!index[term] && bucket[term]) + index[term] = bucket[term]; + } + } + _termIndexes.set(table, index); + return index; + } + function _lookup(table, term, context) { if (!table) return ""; @@ -196,11 +216,7 @@ Singleton { return table[context][term]; if (table[term] && table[term][term]) return table[term][term]; - for (const c in table) { - if (table[c] && table[c][term]) - return table[c][term]; - } - return ""; + return _termIndex(table)[term] || ""; } // isRealContext is consumed by translations/extract_translations.py only: diff --git a/quickshell/Services/AppSearchService.qml b/quickshell/Services/AppSearchService.qml index 6be85baff..eab7db777 100644 --- a/quickshell/Services/AppSearchService.qml +++ b/quickshell/Services/AppSearchService.qml @@ -769,11 +769,7 @@ Singleton { return results; } - function getCategoriesForApp(app) { - if (!app?.categories) - return []; - - const categoryMap = { + readonly property var _categoryMap: ({ "AudioVideo": I18n.tr("Media"), "Audio": I18n.tr("Media"), "Video": I18n.tr("Media"), @@ -798,15 +794,20 @@ Singleton { "Accessories": I18n.tr("Utilities"), "FileManager": I18n.tr("Utilities"), "TerminalEmulator": I18n.tr("Utilities") - }; + }) + + on_CategoryMapChanged: _cachedCategories = null + + function getCategoriesForApp(app) { + if (!app?.categories) + return []; const mappedCategories = new Set(); - for (const cat of app.categories) { - if (categoryMap[cat]) - mappedCategories.add(categoryMap[cat]); + const mapped = _categoryMap[cat]; + if (mapped) + mappedCategories.add(mapped); } - return Array.from(mappedCategories); }