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:
+6
-1
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user