fix: resolve nested i18n keys via dot notation in t()

The locale JSON files use nested structure (e.g. {"nav":{"tasks":"…"}}),
but t() did a flat lookup, always falling back to the raw key string.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Ulas
2026-03-31 23:47:59 +02:00
parent d543837025
commit 752d0f919f
+6 -1
View File
@@ -64,9 +64,14 @@ export async function setLocale(locale) {
window.dispatchEvent(new CustomEvent('locale-changed', { detail: { locale } }));
}
/** Hilfsfunktion: Dot-Notation in verschachteltem Objekt auflösen */
function resolve(obj, key) {
return key.split('.').reduce((o, k) => (o != null ? o[k] : undefined), obj);
}
/** Übersetzungsfunktion mit Platzhalter-Unterstützung {{variable}} */
export function t(key, params = {}) {
let str = translations[key] ?? fallbackTranslations[key] ?? key;
let str = resolve(translations, key) ?? resolve(fallbackTranslations, key) ?? key;
for (const [k, v] of Object.entries(params)) {
str = str.replaceAll(`{{${k}}}`, String(v));
}