diff --git a/frontend/src/lib/i18n/index.ts b/frontend/src/lib/i18n/index.ts index 6d6c009..2545c6d 100644 --- a/frontend/src/lib/i18n/index.ts +++ b/frontend/src/lib/i18n/index.ts @@ -12,6 +12,19 @@ const translations: Record> = { en, ru }; let currentLocale: Locale = 'en'; +// Auto-initialize from localStorage on module load (client-side) +if (typeof localStorage !== 'undefined') { + const saved = localStorage.getItem('locale') as Locale | null; + if (saved && saved in translations) { + currentLocale = saved; + } else if (typeof navigator !== 'undefined') { + const lang = navigator.language.slice(0, 2); + if (lang in translations) { + currentLocale = lang as Locale; + } + } +} + export function getLocale(): Locale { return currentLocale; }