launcher: stop rebuilding the category map per app and index i18n misses

fixes #3345
port 1.6

(cherry picked from commit c76c29139f)
This commit is contained in:
bbedward
2026-09-06 17:40:35 +00:00
committed by dms-ci[bot]
parent e8a755b85d
commit 42912ebe74
2 changed files with 32 additions and 15 deletions
+21 -5
View File
@@ -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:
+11 -10
View File
@@ -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);
}