fix(i18n): handle extended locale subtags like zh-Hans-CN

normalizeLocale now correctly maps Windows-style locale strings
(e.g. "zh-Hans-CN") to "zh-CN" by trying lang-region before falling
back to the base language. Bare "zh" is also mapped to "zh-CN".

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
dev-Flyblue
2026-03-15 15:45:35 +08:00
co-authored by Claude Opus 4.6
parent 6724a1ce6b
commit af94d74ad8
+10 -1
View File
@@ -96,8 +96,17 @@ function normalizeLocale(locale: string | null | undefined): AppLocale {
)
if (canonical) return canonical
// Handle extended subtags like "zh-Hans-CN" → try "zh-CN"
const parts = locale.split('-')
if (parts.length >= 3) {
const langRegion = `${parts[0]}-${parts[parts.length - 1]}`
if (isSupportedLocale(langRegion)) {
return langRegion
}
}
// Language-only fallback (e.g. "zh" matches "zh-CN")
const lang = locale.split('-')[0].toLowerCase()
const lang = parts[0].toLowerCase()
const byLang = SUPPORTED_LOCALES.find((l) => l.split('-')[0].toLowerCase() === lang)
if (byLang) return byLang