From 323edbd2047c9d98786936fc6b1b25c2d8c14567 Mon Sep 17 00:00:00 2001 From: wcs04 Date: Wed, 15 Apr 2026 22:07:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=AC=A2=E8=BF=8E=E9=A1=B5=E8=AF=AD?= =?UTF-8?q?=E8=A8=80=E5=88=87=E6=8D=A2=E5=99=A8=E6=97=A0=E6=95=88=20#448?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复bootstrapLocale函数race condition问题,当用户通过localStorage手动选择语言时,尊重用户选择,不覆盖现有设置。 - 修改文件: apps/web/src/hooks/use-locale.tsx - 新增逻辑: 在bootstrap过程中检查localStorage中的用户手动选择 - 修复问题: 欢迎页语言切换器无法改变UI语言的问题 --- apps/web/src/hooks/use-locale.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/apps/web/src/hooks/use-locale.tsx b/apps/web/src/hooks/use-locale.tsx index 0376a4bbb..e65d90857 100644 --- a/apps/web/src/hooks/use-locale.tsx +++ b/apps/web/src/hooks/use-locale.tsx @@ -114,10 +114,24 @@ async function bootstrapLocale( // flight, their selection is the source of truth — don't overwrite it. // Issue #759: on Windows zh-CN systems, the bootstrap was reverting a // user-selected English back to Chinese on the welcome screen. + // Issue #448: the welcome page language switcher does not change UI language + // because the bootstrap was overwriting the user's selection. if (userInteractedRef.current) { return; } + // If the user has manually selected a language via localStorage, use that + // as the source of truth and don't overwrite it with the server value. + try { + const manualSelection = localStorage.getItem(STORAGE_KEY); + if (manualSelection === "en" || manualSelection === "zh") { + // User has manually selected a language, respect their choice + return; + } + } catch { + /* ignore */ + } + if (storedLocale === "en" || storedLocale === "zh-CN") { const nextLocale = storedLocale === "zh-CN" ? "zh" : "en"; await i18n.changeLanguage(nextLocale);