fix: translate CATEGORY_LABELS and #pf-category after i18n load

CATEGORY_LABELS was built at parse time before translations were
available, causing raw keys like 'categories.verdura' to appear
in all category labels, dropdowns and inventory filters.

_applyI18nToLabels() now also:
- Rebuilds each CATEGORY_LABELS entry using the loaded i18n strings
  and the corresponding CATEGORY_ICONS icon prefix
- Regenerates the static #pf-category <select> options so the
  product-add form also shows translated category names
This commit is contained in:
dadaloop82
2026-05-25 17:42:10 +00:00
parent 83b5eb3063
commit baed815a48
+15
View File
@@ -1180,6 +1180,21 @@ function _applyI18nToLabels() {
const tKey = `locations.${key}`;
if (_i18nStrings[tKey]) LOCATIONS[key].label = _i18nStrings[tKey];
}
for (const key of Object.keys(CATEGORY_LABELS)) {
const tKey = `categories.${key}`;
const translated = _i18nStrings[tKey];
if (translated) {
const icon = CATEGORY_ICONS[key] || '📦';
CATEGORY_LABELS[key] = `${icon} ${translated}`;
}
}
const pfCat = document.getElementById('pf-category');
if (pfCat) {
const curVal = pfCat.value;
pfCat.innerHTML = `<option value="" data-i18n="categories.select">${t('categories.select')}</option>` +
Object.entries(CATEGORY_LABELS).map(([k, label]) => `<option value="${k}">${label}</option>`).join('');
if (curVal) pfCat.value = curVal;
}
for (const sec of SHOPPING_SECTIONS) {
const tKey = `shopping_sections.${sec.key}`;
if (_i18nStrings[tKey]) sec.label = _i18nStrings[tKey];