feat(login): add language dropdown, browser auto-detection and configurable default

Replace the language cycling button on the login page with a dropdown
showing all 14 supported languages. Add automatic browser/OS language
detection via navigator.languages, falling back to a configurable
DEFAULT_LANGUAGE env var, then 'en' as last resort.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Isaias Tavares
2026-04-11 17:54:50 -03:00
parent 34df665944
commit 57503a6a10
8 changed files with 130 additions and 28 deletions
+21
View File
@@ -51,6 +51,27 @@ export function isRtlLanguage(language: string): boolean {
return RTL_LANGUAGES.has(language)
}
// Detects the user's preferred language from the browser/OS settings and maps
// it to one of the supported language codes. Returns null if no match is found.
export function detectBrowserLanguage(): string | null {
const browserLangs = navigator.languages?.length ? navigator.languages : [navigator.language]
const supported = SUPPORTED_LANGUAGES.map(l => l.value)
for (const lang of browserLangs) {
// Exact match (e.g. 'de', 'zh-TW')
if (supported.includes(lang)) return lang
// Portuguese variants → our code is 'br' (pt-BR)
if (lang.startsWith('pt')) return 'br'
// Prefix match (e.g. 'de-AT' → 'de', 'zh-CN' → 'zh')
const prefix = lang.split('-')[0]
if (supported.includes(prefix)) return prefix
}
return null
}
interface TranslationContextValue {
t: (key: string, params?: Record<string, string | number>) => string
language: string
+1
View File
@@ -4,5 +4,6 @@ export {
getLocaleForLanguage,
getIntlLanguage,
isRtlLanguage,
detectBrowserLanguage,
SUPPORTED_LANGUAGES,
} from './TranslationContext'