INNER CODE UNIT · TypeScript
normalizeLocale
evolution-foundation/evo-nexus · dashboard/frontend/src/i18n/index.ts:43
export function normalizeLocale(raw: string | null | undefined): SupportedLocale {
if (!raw) return DEFAULT_LOCALE
const cleaned = String(raw).trim().replace('_', '-')
// Exact match wins
if ((SUPPORTED_LOCALES as readonly string[]).includes(cleaned)) {
return cleaned as SupportedLocale
}
// Legacy "ptBR" without hyphen
if (/^ptBR$/i.test(cleaned)) return 'pt-BR'
if (/^enUS$/i.test(cleaned)) return 'en-US'
// Language-only codes → pick the regional variant we ship
const lang = cleaned.toLowerCase().split('-')[0]
if (lang === 'pt') return 'pt-BR'
if (lang === 'en') return 'en-US'
if (lang === 'es') return 'es'