Internationalization
Internationalization
The web UI supports zh-CN and en. Chinese is the default for every visitor; the site does not automatically choose a language from the browser.
Switching languages
The language switcher in the navigation toggles between Chinese and English. The
choice is stored in localStorage under leaderboard.locale and restored on the
next visit. Switching does not change the URL, and the initial HTML is always
Chinese because the site is statically exported.
Message catalogs
Messages live in apps/leaderboard-web/lib/i18n/messages/en.ts. Keys are the
Chinese source strings; the English catalog maps each Chinese key to its English
text. The zh-CN lookup falls back to the key itself, and the English lookup falls
back to zh-CN and then the key.
To add a message:
- Add the Chinese source string to
en.tsand its English translation. - Use
t("中文文案")in a client component, or<T k="中文文案" />in a server component. - Use named parameters such as
{count}and pass them witht("共 {count} 位跑者", { count }).
Data values (runner names, event names, badge names) are not translated. Docs content and server metadata remain in their authored language.
Scope and limitations
- UI copy only: navigation, pages, forms, charts, empty/error/loading states.
- No locale-prefixed routes or middleware; this keeps
output: "export"working. - English is applied after hydration, so a visitor with a saved English preference may briefly see the Chinese HTML.
- Add new keys to both languages; the catalog test checks English values and interpolation.