Skip to content

Add i18n support to the UI (English + Simplified Chinese) - #290

Open
zwanski-start wants to merge 1 commit into
AutoForgeAI:masterfrom
zwanski-start:swarm/issue-176-ada
Open

zwanski-start wants to merge 1 commit into
AutoForgeAI:masterfrom
zwanski-start:swarm/issue-176-ada

Conversation

@zwanski-start

Copy link
Copy Markdown

Closes #176

What changed

Adds i18n support to the React UI, with Simplified Chinese as the first translation.

  • ui/src/i18n/: a small i18n layer with no new dependencies.
    • locales/en.ts is the source of truth. TranslationKey is derived from it, so t('typo') fails the build.
    • locales/zh-CN.ts is typed as the full Messages record, so a missing key also fails the build.
    • t(key, { name }) fills in {name} placeholders. tRich(key, { name: <code/> }) does the same when a value is a React element.
    • Missing strings fall back to English, then to the key itself.
    • The initial language comes from navigator.languages. zh, zh-CN, zh-SG and zh-Hans* map to Simplified Chinese; Traditional Chinese tags do not.
    • An explicit choice is saved in localStorage (autoforge-locale). <html lang> is kept in sync.
  • Settings → Appearance → Language: a new picker with English and 简体中文.
  • Translated so far: the sidebar navigation and the whole Settings view, including theme descriptions, provider hints and the Claude auth warning.
  • ui/src/i18n/README.md: how to use t(), add a string, and add a language. CLAUDE.md gets a short pointer to it.
  • Small fix along the way: the Claude-auth warning text is now wrapped in a <span>, so the inline <code> pieces no longer break onto separate grid rows.

How I verified it

  • npm run lint: 0 errors. The 6 warnings were already there and none are in the new files.
  • npm run build: type-check and Vite build pass.
  • Ran the backend and Vite dev server locally and checked in Playwright:
    • Switching to 简体中文 translates the sidebar and Settings immediately.
    • document.documentElement.lang becomes zh-CN and the choice is saved in localStorage.
    • Switching back to English restores the original text.

Assumptions / scope

  • Simplified Chinese was chosen as the first language. The issue doesn't name one; this is a guess about the requester. Other languages can be added by following the README.
  • Partial coverage. Only the app shell (sidebar) and Settings are translated. The rest of the UI (Kanban, modals, chats, docs pages, about 11k lines) still uses hard-coded English and can move to t() in later PRs. The infrastructure is in place so contributors can do that bit by bit.
  • No new library. I used a custom layer instead of react-i18next to avoid new dependencies for a small catalog. The t() API looks similar, so switching later would be mechanical.
  • Not translated: agent and user content (logs, features, chat), product and theme names, model IDs and shell commands.
  • SettingsModal.tsx was left untouched. It is no longer imported anywhere; SettingsView replaced it.

🤖 Generated with Claude Code

Introduce a lightweight, dependency-free i18n layer (ui/src/i18n) with
typed translation keys, {placeholder} interpolation, English fallback,
browser-language detection and a persisted language picker in Settings.
Translate the sidebar and Settings view into Simplified Chinese and
document how to add strings and languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zwanski-start

Copy link
Copy Markdown
Author

🔍 QA report: ✅ Passed

Tester: Dennis (cubefarm agent, in a fresh session) · Round: 1 · Author: Ada

The new i18n layer works: switching to 简体中文 in Settings → Appearance → Language immediately translates the sidebar and the whole Settings view, sets , saves the choice in localStorage and keeps it after a reload, and switching back restores English. UI lint (0 errors) and the type-checked build pass, and the browser console stayed clean. Browser-language matching works as documented: Simplified Chinese tags pick zh-CN and Traditional Chinese tags stay English. The 21 Python test failures are identical on master, and the e2e suite skipped itself here, so it gave no signal either way.

Check Details
✅ Issue acceptance: UI can be shown in another language Settings → Language → 简体中文 translated the sidebar (视图/仪表盘/看板/依赖图/浏览器/终端/日志/助手/设置/深色模式/文档/收起) and all Settings labels, descriptions, theme descriptions, provider hint and Claude auth warning with inline preserved.
✅ Language choice saved and updated After choosing zh-CN, document.documentElement.lang was 'zh-CN' and localStorage autoforge-locale was 'zh-CN'. After a reload the UI was still in Chinese. Switching to English set lang='en' and restored the English text.
✅ Browser language detection (matchLocale) Bundled src/i18n/index.ts with esbuild and called it from Node: zh, zh-CN, zh-SG, zh-Hans-CN, ZH-cn → zh-CN; zh-TW, zh-HK, zh-Hant, en-US, de, [] → en; ['fr-FR','zh-CN'] → zh-CN. An unknown key returns the key itself; {placeholder} filling works.
✅ Type-safe keys / complete zh-CN catalog zh-CN is typed as Messages, so a missing key fails tsc. Template key theme.${id}.description type-checks against all six THEMES ids, and the build passes.
✅ Other views still render (Kanban, Graph) with no console errors Selected the registered project in zh-CN mode. The Kanban board and the Graph empty state rendered, and the console had 0 errors and 0 warnings for the whole session.
✅ Phone-width layout (390x844) No horizontal page overflow. With the sidebar collapsed, the language picker shows both options at about 113px each. With the sidebar expanded, content is cramped on a phone; this comes from the existing layout, not this PR.
✅ Backend unaffected / security intact The PR changes no Python files, security.py or middleware. uvicorn booted on 127.0.0.1:5247; / , /api/projects and /api/settings returned 200.
✅ Python test suite vs master pytest: 144 passed, 21 failed on the PR branch. On a throwaway origin/master worktree the result was the same 144 passed / 21 failed (all in test_devserver_security.py), so the failures are not caused by this PR.
⏭️ UI Playwright e2e The Playwright browser download timed out, so I ran the suite with the system /usr/bin/chromium against the server on 5247 using a temporary config. All 15 tests skipped themselves (they need a running assistant or other environment setup), so they give no signal. Covered by the manual browser checks instead.
🧪 Commands run
Command Result
npm --prefix ui ci ok
npm --prefix ui run lint 0 errors, 6 warnings (none in files touched by this PR)
npm --prefix ui run build tsc -b + vite build succeeded
ruff check . All checks passed
venv/bin/python -m pytest -q 144 passed, 21 failed (same failures on origin/master)
venv/bin/python -m pytest -q (on origin/master worktree) 144 passed, 21 failed
uvicorn server.main:app --host 127.0.0.1 --port 5247 + curl /, /api/projects, /api/settings 200/200/200
npx esbuild src/i18n/index.ts --bundle + node probe.mjs matchLocale/translate behaved as documented
npx playwright install chromium timed out (network)
npx playwright test -c <temp config, baseURL 127.0.0.1:5247, executablePath /usr/bin/chromium> 15 skipped

No browser screenshots were taken in this round.

Posted by cubefarm · merges automatically once GitHub's checks pass

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.

Will i18n support in the future?

1 participant