Date: 2026-01-11 00:52
Summary: Fixed language switcher so explicit /en/ and /zh/ URLs are not overridden by Accept-Language redirects.
[question] 页面点击选择英文语言,页面不生效,应该选择后显示对应的语言的页面
[try to solve]
Root cause: / negotiated language via Accept-Language. With a Chinese-preferring browser, clicking “English” to / immediately 302’d back to /zh/, so the switch appeared broken.
Fix: use stable explicit language URLs (/en/, /zh/) for the language dropdown; always serve the matching language on those paths (do not redirect default language back to /); adjust the static client script to respect any language prefix, including the default.
Verify: with Accept-Language: zh, /en/ returns 200 with no redirect; / still 302s to /zh/.
[actions]
- Updated:
scripts/site/config.mjs(withExplicitLangPath) - Updated:
scripts/build-site.mjs(language switch links use explicit paths) - Updated:
scripts/site/layout.mjs(client script respects any lang prefix) - Updated:
src/index.ts(/en/,/zh/no longer bounce to/) - Updated:
src/pages/websiteHeadersPage.ts(tool page switcher uses explicit paths) - Ran:
env SITE_LANGS=zh,en SITE_DEFAULT_LANG=en npm run build:site