From 07a06227ca9104b8d1fa33740e459cfe4ead5cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E9=98=BF=E6=B1=9F=28Relakkes?= =?UTF-8?q?=29?= Date: Wed, 29 Jul 2026 09:23:19 +0800 Subject: [PATCH] feat(site): pick the docs language from the browser on first visit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The site already ships both languages, but / always served Chinese, so English readers had to find the switcher themselves. A Chinese browser now stays on /, everything else lands on /en. The decision runs as an inline script in index.html, next to the existing theme anti-flash block: deferring it to React would show English readers a full screen of Chinese first. It only fires on the root path — /en, /start and /en/start are deliberate destinations, and redirecting those would kick readers off any cross-language link they follow. A manual switch is stored in localStorage and wins over the browser language, otherwise switching would be undone on the next visit to the home page. resolveRootRedirect carries the same rules as a testable pure function. check-docs asserts the inline copy and the module agree on the storage key, the Chinese tag pattern and the root-only guard, so the two cannot drift. --- site/index.html | 23 +++++++++ site/package.json | 3 +- site/scripts/check-docs.mjs | 36 ++++++++++++- site/src/components/SiteHeader.jsx | 12 ++++- site/src/lib/locale.js | 48 +++++++++++++++++ site/src/lib/locale.test.js | 82 ++++++++++++++++++++++++++++++ site/src/pages/home/HomePage.jsx | 8 ++- 7 files changed, 208 insertions(+), 4 deletions(-) create mode 100644 site/src/lib/locale.js create mode 100644 site/src/lib/locale.test.js diff --git a/site/index.html b/site/index.html index fc4d54b9..f81811ad 100644 --- a/site/index.html +++ b/site/index.html @@ -16,6 +16,29 @@ Claude Code Haha — Claude Code 的本地优先桌面客户端 +