From 752d0f919fe9ed3e03201ae3aee5cb2040d9fc49 Mon Sep 17 00:00:00 2001 From: Ulas Date: Tue, 31 Mar 2026 23:47:59 +0200 Subject: [PATCH] fix: resolve nested i18n keys via dot notation in t() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- public/i18n.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/public/i18n.js b/public/i18n.js index 5c45e41..49981e0 100644 --- a/public/i18n.js +++ b/public/i18n.js @@ -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)); }