Skip to content

🌐 feat: Add Simplified Chinese (zh-Hans) localization + language setting - #148

Open
SwakinX wants to merge 3 commits into
LibreChat-AI:mainfrom
SwakinX:feat/zh-hans-localization
Open

SwakinX wants to merge 3 commits into
LibreChat-AI:mainfrom
SwakinX:feat/zh-hans-localization

Conversation

@SwakinX

@SwakinX SwakinX commented Sep 24, 2026

Copy link
Copy Markdown

Summary

  • Add a complete Simplified Chinese (zh-Hans) locale covering the full English key set,
    with terminology aligned to the LibreChat main zh-Hans translation (shared com_*
    strings reuse the official wording so the panel and chat UI read consistently)
  • Add a language setting to the settings dialog — a Select dropdown (English /
    中文(简体)) below the theme row, persisting the choice via the i18nextLng
    cache key and keeping document.documentElement.lang in sync
  • Localize two dropdowns that rendered raw enum values (create-user role select
    showed USER/ADMIN; audit-log target-type filter showed raw principal types)

Locale detection

Detection is adapted from the LibreChat client implementation
(client/src/locales/i18n.ts): explicit stored choice wins, then navigator language,
normalized through an alias table (zh, zh-CN, zh-SG → zh-Hans). This replaces
i18next-browser-languagedetector, whose nonExplicitSupportedLngs handling strips
zh-Hans to zh before the whitelist check — meaning a registered zh-Hans locale
could never actually be resolved.

SSR renders the pre-hydration loading shell in the default locale deterministically,
and the shell text suppresses the expected hydration mismatch (<html lang> already
had suppressHydrationWarning).

Tests

  • New src/locales/locales.test.ts guards en/zh key-set parity, interpolation
    placeholder parity, language switching (incl. zh-CN/zh resolution), and
    locale normalization
  • Full suite passes (bun run test, 831 tests)

Notes for reviewers

Three commits, intentionally split for reviewability:

  1. 🌐 feat: Add Simplified Chinese (zh-Hans) locale
  2. 🌐 feat: Add language setting to settings dialog
  3. 🐛 fix: Localize role and target type dropdown options

Happy to adjust the translation wording or split/merge commits as preferred.

- Add src/locales/zh-Hans/translation.json covering the full en key set
  (terminology aligned with the LibreChat main zh-Hans translation)
- Register zh-Hans in i18n init with LibreChat-style locale normalization
  and detection (stored choice > navigator, alias mapping zh/zh-CN/zh-SG),
  replacing the browser-languagedetector whose nonExplicitSupportedLngs
  handling rejected zh-Hans
- Render the SSR loading shell in the default locale deterministically and
  suppress the expected hydration text mismatch
- Guard en/zh key-set and placeholder parity plus language switching in
  locales.test.ts
- Add a language row with a Select dropdown (English / 中文(简体)) below
  the theme row, reusing the existing click-ui Select component
- Persist the choice via i18nextLng (the detection cache key) and keep
  document.documentElement.lang in sync
- CreateUserDialog role select rendered raw SystemRoles values
  (USER/ADMIN); use localized labels instead
- Audit log target-type filter rendered raw PrincipalType enum values;
  map them to localized labels
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant