From c53d445b8683f38974441c6d774c57301b6df922 Mon Sep 17 00:00:00 2001 From: "[dyad]" Date: Sun, 18 Jan 2026 16:03:24 +0100 Subject: [PATCH] [dyad] Fixing the translation logic - wrote 1 file(s) --- src/context/i18n-context.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/context/i18n-context.tsx b/src/context/i18n-context.tsx index 5135b47..59a54ff 100644 --- a/src/context/i18n-context.tsx +++ b/src/context/i18n-context.tsx @@ -12,7 +12,7 @@ interface I18nContextType { const I18nContext = createContext(undefined); -const translations: { [key: string]: { [key: string]: string } } = { +const translations: { [key: string]: any } = { en, de, }; @@ -21,13 +21,21 @@ export function I18nProvider({ children }: { children: ReactNode }) { const [language, setLanguage] = useState('en'); const t = (key: string, params?: { [key: string]: string | number }) => { - let translation = translations[language]?.[key] || key; + const translation = key.split('.').reduce((acc, currentKey) => { + if (acc && typeof acc === 'object' && currentKey in acc) { + return acc[currentKey]; + } + return undefined; + }, translations[language]); + + let result = (typeof translation === 'string' ? translation : key); + if (params) { Object.keys(params).forEach(paramKey => { - translation = translation.replace(`{${paramKey}}`, String(params[paramKey])); + result = result.replace(`{${paramKey}}`, String(params[paramKey])); }); } - return translation; + return result; }; return (