Skip to content

web: add UI translation layer and Turkish locale - #346

Merged
BaaRai merged 3 commits into
BaaRai:mainfrom
mervedalgin:i18n-turkish
Nov 19, 2026
Merged

BaaRai merged 3 commits into
BaaRai:mainfrom
mervedalgin:i18n-turkish

Conversation

@mervedalgin

Copy link
Copy Markdown
Contributor

Problem

The web UI only exists in English, and every string is hard-coded in the components, so it can't be offered in another language. A few spots also hard-code zh-CN date formatting, and one approval button reads "Toujours autoriser".

Change

  • Translation layer, web/src/i18n/index.ts.
    • t(key, vars) takes the English source text as the key and returns the string for the active locale.
    • A missing entry falls back to English, so an incomplete dictionary never breaks the UI.
    • Placeholders use {name}.
  • Locale selection.
    • The locale is chosen once per page load: a saved choice, otherwise the browser language, otherwise English.
    • A new Language toggle under Preferences saves the choice and reloads the page.
    • Because the locale never changes while a page is open, t() is a plain function. It also works in module constants, column definitions, toasts and lib/ helpers, with no hooks or context and nothing for the React Compiler to track.
  • Turkish, web/src/i18n/locales/tr.json. One flat file with about 2,600 entries. To add a language, add locales/<code>.json and list it in LOCALES.
  • Wrapping. Display text in web/src now goes through t(): JSX text, placeholders, titles, aria-labels, toasts, displayed errors, option and column labels, and empty states.
  • Sentence templates. Sentences that were built from fragments, and English plural branches, are now single templates so other languages can reorder words. Where a sentence contains <b> or <code>, the markup stays inside the translated string and a small local helper renders it.

Visible changes for English users

  • Hard-coded zh-CN dates, and dates with no explicit locale, now follow the UI locale (intlLocale). formatCurrency and the calendar default to it as well. The date-range picker label now reads "Nov 18, 2026" instead of "18 Nov 2026".
  • A few error toasts and labels were reworded so they read as one template, for example export: 500 became "Export failed: 500".
  • Some delete-dialog sentences that had a bold or monospace span in the middle are now plain text. This also fixes a missing space ("This taskwill be…").
  • Icon-only buttons in the agent editor and the preferences toggles now have aria-labels.
  • "Toujours autoriser" is now "Always allow".

Deliberately left in English

  • Values sent to the API or compared in code: enum and status values, keys, DSL syntax, the @[kind#id …] mention labels (parsed back by lib/chat-mentions), and technical labels such as HTTP methods, IP/CIDR, URL and tool names.
  • Agent prompts and anything else sent to the model.
  • Data from the backend: worker and agent names, tool descriptions, backend error messages and logs.
  • The browser extension.

Testing

All on this branch's HEAD:

  • npx tsc --noEmit is clean. biome lint reports the same findings as main.
  • A script checked that every literal t("…") key has a tr.json entry with the same {placeholders}.
  • npm run test:polling, test:replay, test:upload and node --test src/lib/chat-mentions.test.mjs all pass. upload.test.mjs needed a stub for the new @/i18n import.
  • Mock mode (NEXT_PUBLIC_MOCK=1) in headless Edge, with fresh profiles for --lang=tr and --lang=en-US:
    • 25 routes rendered: all main pages, login, setup and an unknown route.
    • I extracted the visible text and console output for each.
    • Turkish browsers get Turkish and English browsers get English. The only English left in Turkish mode is mock data.
    • There were no hydration errors once not-found was changed to render its text after mount, which is the second commit.
    • /system/settings and /system/notify throw in mock mode on main too, because the mock data has no hosts / kinds. This PR does not change that.
  • I built the embedded binary (go build -tags embedui) and ran it against PostgreSQL. Pages are served correctly. I have not clicked through every screen while logged in against a real backend, so a review pass in Turkish would be welcome.

Known limitations

  • The <title> comes from static metadata, so it is fixed at build time in English.
  • The login "checking" state is prerendered in English. For a non-English reader it uses suppressHydrationWarning for that brief moment.
  • In lib/preferences/theme.ts, the t("Default") label sits inside the generated:themePresets block. Rerunning generate:presets would drop it.

Size

This touches about 100 files, more than CONTRIBUTING asks for. The wrapping and the dictionary don't separate well, because wrapped keys without a dictionary just show English. If you prefer, I can split it into:

  1. the i18n layer, the language toggle and the date-locale fixes;
  2. the wrapping plus tr.json.

I can also split it by area.

🤖 Generated with Claude Code

mervedalgin and others added 3 commits November 18, 2026 22:03
Every user-visible string in the web UI now goes through t() from
web/src/i18n. The English source text is the key, so a missing entry
falls back to English and nothing breaks; Turkish lives in one flat
file, web/src/i18n/locales/tr.json (about 2,600 entries).

The locale is chosen once per page load: a saved choice, else the
browser language, else English. Switching (new Language toggle under
Preferences) stores the choice and reloads, so t() also works in module
constants, helpers and toasts without hooks.

Also:
- hard-coded zh-CN / implicit date locales now follow the UI language
- sentences assembled from fragments became single templates
- "Toujours autoriser" in approval records is now English
- upload.test.mjs stubs the new @/i18n import

Values sent to the API or compared in code, agent prompts, and backend
messages are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
not-found is prerendered in the build-time locale, so a reader whose
browser picks another locale hit a hydration mismatch. Render the
translated text after mount instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n CI

t() looked a key up with dict[key] ?? key, so t("constructor") returned
Object and t("toString", {}) threw. Backend values are used as keys, so
this was reachable. Use an own-property check for the dictionary and the
vars, and commit the key-check script as npm run test:i18n in the web
job so tr.json cannot drift.

@BaaRai BaaRai left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied two fixes at d577d7e: t() now uses an own-property check for the dictionary and for vars, so prototype keys cannot resolve or throw, and the key-check script is committed as npm run test:i18n in the web job (2,542 literal keys checked against 2,600 entries). The rest of the review holds; merging after the web job.

@BaaRai
BaaRai merged commit e5fe5b2 into BaaRai:main Nov 19, 2026
5 checks passed
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.

2 participants