From af94d74ad8d9c675ff01d9e5640d28eb58b668eb Mon Sep 17 00:00:00 2001 From: dev-Flyblue <1077373674@qq.com> Date: Sun, 15 Mar 2026 13:22:43 +0800 Subject: [PATCH] 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) --- src/contexts/I18nContext.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/contexts/I18nContext.tsx b/src/contexts/I18nContext.tsx index de9d139b..77670801 100644 --- a/src/contexts/I18nContext.tsx +++ b/src/contexts/I18nContext.tsx @@ -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