Skip to content

Commit 7598e17

Browse files
author
wcs04
committed
fix: 欢迎页语言切换器无效 #448
修复bootstrapLocale函数race condition问题,当用户通过localStorage手动选择语言时,尊重用户选择,不覆盖现有设置。 - 修改文件: apps/web/src/hooks/use-locale.tsx - 新增逻辑: 在bootstrap过程中检查localStorage中的用户手动选择 - 修复问题: 欢迎页语言切换器无法改变UI语言的问题
1 parent dadfb1c commit 7598e17

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

apps/web/src/hooks/use-locale.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,24 @@ async function bootstrapLocale(
114114
// flight, their selection is the source of truth — don't overwrite it.
115115
// Issue #759: on Windows zh-CN systems, the bootstrap was reverting a
116116
// user-selected English back to Chinese on the welcome screen.
117+
// Issue #448: the welcome page language switcher does not change UI language
118+
// because the bootstrap was overwriting the user's selection.
117119
if (userInteractedRef.current) {
118120
return;
119121
}
120122

123+
// If the user has manually selected a language via localStorage, use that
124+
// as the source of truth and don't overwrite it with the server value.
125+
try {
126+
const manualSelection = localStorage.getItem(STORAGE_KEY);
127+
if (manualSelection === "en" || manualSelection === "zh") {
128+
// User has manually selected a language, respect their choice
129+
return;
130+
}
131+
} catch {
132+
/* ignore */
133+
}
134+
121135
if (storedLocale === "en" || storedLocale === "zh-CN") {
122136
const nextLocale = storedLocale === "zh-CN" ? "zh" : "en";
123137
await i18n.changeLanguage(nextLocale);

0 commit comments

Comments
 (0)