Skip to content

feat: internationalization (i18n) support with i18next + Simplified Chinese locale - #97

Open
JaneConan wants to merge 1 commit into
microsoft:mainfrom
JaneConan:feat/i18n
Open

feat: internationalization (i18n) support with i18next + Simplified Chinese locale#97
JaneConan wants to merge 1 commit into
microsoft:mainfrom
JaneConan:feat/i18n

Conversation

@JaneConan

Copy link
Copy Markdown

Summary

This PR adds internationalization support to Ontology Playground using
i18next / react-i18next, and ships Simplified
Chinese (zh-CN) as the first additional locale.

Motivation

Ontology Playground is a great learning tool, but all UI strings are
hardcoded in English. This PR extracts them into locale resources so the
community can contribute translations, lowering the barrier for non-English
learners (the ontology/knowledge-graph learning audience is very global).

What's changed

  • New src/i18n/ module (no build-config changes):
    • index.ts — i18next init: follows the OS/browser language by default,
      persists manual choice to localStorage (op-lang), falls back to English
    • locales/en.ts / locales/zh-CN.ts — ~230 keys each, kept as TS modules
      (no resolveJsonModule / tsconfig changes needed)
    • LanguageSwitcher.tsx — a small 🌐 dropdown, mounted at the right end of
      the header
  • String extraction: hardcoded UI strings in App.tsx, Header.tsx and
    18 components (modals, panels, designer/*, LearnPage chrome) are wrapped
    with t(). Replacements are minimal and inline — no logic or markup
    restructuring — to keep this diff reviewable.
  • Dependencies: i18next, react-i18next, i18next-browser-languagedetector
    (~15 kB gzip total added to the bundle).

What's NOT changed

  • Learn course content under content/learn/ (Markdown) is untouched —
    course translation is a much larger effort and better handled separately.
  • No changes to build config, CI, or tsconfig.
  • English UI is pixel-identical when locale is en (pure refactor path).

Testing

  • npm run build passes (tsc type-check + vite build + embed build)
  • Manually verified both locales via vite preview: command palette, header
    actions/themes, all modals/panels render correctly in en and zh-CN
  • Language choice persists across reloads; unsupported locales fall back to en

Notes for reviewers

  • Key naming is namespaced per component (header.*, welcome.*, quest.*, …)
  • Adding a new language = adding one file under src/i18n/locales/ and one
    entry to SUPPORTED_LANGUAGES
  • Happy to split this PR (infrastructure first, zh-CN second) if you prefer
    smaller reviews

- Add src/i18n/ (i18next init, en/zh-CN locale resources, LanguageSwitcher)
- Wrap hardcoded UI strings across App/Header and 18 components with t()
- Mount I18nextProvider in main.tsx
- Language switcher is always visible in the header (globe + select pill),
  works on both desktop and mobile, persists choice via localStorage
- zh-CN resolves correctly with explicit supportedLngs (no nonExplicit fallback);
  <html lang> synced on change for a11y/SEO
- deps: i18next, react-i18next, i18next-browser-languagedetector
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