From 8eac858bd6aece49b27a3b2c29e635a2d9c28470 Mon Sep 17 00:00:00 2001 From: snomiao Date: Fri, 22 Aug 2025 04:48:14 +0000 Subject: [PATCH] [bugfix] Fix Chinese locale detection to properly handle traditional Chinese MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update getDefaultLocale() to distinguish between zh-CN (simplified) and zh-TW/zh-HK/zh-Hant (traditional) - Fixes issue where browsers set to traditional Chinese were incorrectly defaulting to simplified Chinese translations - Preserves existing behavior for all other languages Fixes #5151 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/i18n.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/i18n.ts b/src/i18n.ts index 08369af621..20a53300a2 100644 --- a/src/i18n.ts +++ b/src/i18n.ts @@ -58,10 +58,26 @@ const messages = { ar: buildLocale(ar, arNodes, arCommands, arSettings) } +function getDefaultLocale(): string { + const lang = navigator.language + + // Handle Chinese variants specifically to distinguish between simplified and traditional + if (lang.startsWith('zh-')) { + return lang.startsWith('zh-TW') || + lang.startsWith('zh-HK') || + lang.startsWith('zh-Hant') + ? 'zh-TW' + : 'zh' + } + + // For other languages, use the existing logic + return lang.split('-')[0] || 'en' +} + export const i18n = createI18n({ // Must set `false`, as Vue I18n Legacy API is for Vue 2 legacy: false, - locale: navigator.language.split('-')[0] || 'en', + locale: getDefaultLocale(), fallbackLocale: 'en', messages, // Ignore warnings for locale options as each option is in its own language.