diff --git a/frontend/src/i18n/setup.ts b/frontend/src/i18n/setup.ts index dc3a6074..93e620e4 100644 --- a/frontend/src/i18n/setup.ts +++ b/frontend/src/i18n/setup.ts @@ -44,9 +44,18 @@ Object.entries(localeFiles).forEach(([path, module]) => { }) const getStoredLanguage = (): string => { + let stored: string | null = null try { - const stored = localStorage.getItem('altsendme-language') - return stored || 'en' + stored = localStorage.getItem('altsendme-language') + } catch { + // Continue with browser-locale detection when storage is unavailable. + } + + try { + const tag = (navigator.language || 'en').toLowerCase() + const keys = Object.keys(resources) + const pick = (t: string) => keys.find((k) => k.toLowerCase().startsWith(t)) + return stored || pick(tag) || pick(tag.slice(0, 2)) || 'en' } catch { return 'en' }