Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(i18n): fix zh-CN language switching and LanguageSwitcher display

hoc.s18d97e8befa8
diff --git a/frontend/src/components/layout/Layout.tsx b/frontend/src/components/layout/Layout.tsx
index 5559f418d..e760c3145 100644
--- a/frontend/src/components/layout/Layout.tsx
+++ b/frontend/src/components/layout/Layout.tsx
@@ -337,11 +337,15 @@ function LanguageSwitcher() {
};
}, [open]);
- // i18n.language may be a regional variant like "ja-JP" even though only
- // "ja" is in SUPPORTED_LANGUAGES (nonExplicitSupportedLngs resolves the
- // resources but keeps the full code). The i18n.languages array contains
- // both the detected and resolved codes, so we match against any entry.
+ // i18n.language (singular) is the primary active language. We try an exact
+ // match first against SUPPORTED_LANGUAGES. If that fails (e.g. a regional
+ // variant like "ja-JP"), we fall back to i18n.languages (plural) which
+ // includes both the detected and resolved codes. NOTE: i18n.languages
+ // always contains the fallback language ("en"), so it must NOT be the
+ // primary match — otherwise "en" being first in SUPPORTED_LANGUAGES
+ // would always win and the switcher would never show any other language.
const current =
+ SUPPORTED_LANGUAGES.find((l) => l.code === i18n.language) ??
SUPPORTED_LANGUAGES.find((l) => i18n.languages?.includes(l.code)) ??
SUPPORTED_LANGUAGES[0];
diff --git a/frontend/src/i18n/index.ts b/frontend/src/i18n/index.ts
index ccac27ec9..e171655e0 100644
--- a/frontend/src/i18n/index.ts
+++ b/frontend/src/i18n/index.ts
@@ -54,8 +54,9 @@ i18n
// removed.
fallbackLng: "en",
supportedLngs: SUPPORTED_LANGUAGES.map((l) => l.code),
- // Allow "en-US" → "en", "ja-JP" → "ja", etc.
- nonExplicitSupportedLngs: true,
+ // NOTE: Intentionally NOT using nonExplicitSupportedLngs — it strips
+ // region codes from compound language keys like "zh-CN" which causes
+ // isSupportedCode to reject them ("zh-CN" → "zh", not in supportedLngs).
interpolation: { escapeValue: false },
detection: {
// In browsers the navigator.language gives the user's browser locale,
diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts
index 2a8a3a89a..03ee4fef6 100644
--- a/frontend/vite.config.ts
+++ b/frontend/vite.config.ts
@@ -13,7 +13,8 @@ const PROXY_PATHS = [
"/live",
"/upload",
"/shadow-reports",
-];
+ "/channels",
+]
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");