Skip to content

refactor(i18n): centralize locale-aware rendering - #41432

Open
opencode-agent[bot] wants to merge 1 commit into
devfrom
weekly-i18n-aug10
Open

refactor(i18n): centralize locale-aware rendering#41432
opencode-agent[bot] wants to merge 1 commit into
devfrom
weekly-i18n-aug10

Conversation

@opencode-agent

@opencode-agent opencode-agent Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • centralize runtime-English fallback, rich template insertion, and plural template selection in the shared typed UI i18n context
  • replace locale-aware component logic and grammatical prefix/suffix dictionaries with complete phrase templates
  • migrate all 62 UI dictionaries mechanically without changing rendered phrase order or spacing
  • translate retained English “Web Search” labels in Bengali, Dzongkha, Nepali, Shahmukhi Punjabi, and Sinhala, plus one embedded English Sinhala action
  • document the locale-unaware component boundary in UI and session UI guidance

Audit evidence

The weekly audit ran against dev at 0bff28de0910 and covered the app, shared UI, session UI, and desktop translation surfaces.

Dictionary parity was already clean across English plus 61 non-English locales, including placeholders, CLDR plural categories, desktop-native bundles, locale detection, and ICU support. The deeper invariant scan found:

  1. AnimatedCountLabel selected CLDR categories and constructed .one / .other lookup keys in component code. Its singular/other suffix algorithm also assumed English-like morphology and ignored zero, two, few, and many transitions.
  2. The usage-limit dialog branched on locale() === "en" in feature code to choose runtime English payloads versus dictionary copy.
  3. Line-comment and filtered-list copy was split across six grammatical prefix/suffix keys, requiring components to assemble sentences.
  4. Five locale files retained unexplained English Web Search / {{provider}} Web Search pairs, and Sinhala retained English Render inside a translated action.

The production-string scan found no additional high-confidence hardcoded web or desktop copy after excluding tests, developer-only UI, product/provider/tool names, URLs, code tokens, keyboard legends, acronyms, assets, and established technical borrowings.

Shared API

createUiI18n(...) now enriches the existing translation source with three narrow operations:

  • tDynamic(key, source, params) preserves runtime-generated English copy for English locale tags and selects dictionary copy for other locales.
  • parts(key, slots) inserts typed rich values into complete phrase templates in dictionary-authored order.
  • pluralParts(key, count, slots, params) selects the CLDR plural template and inserts an animated count without exposing categories or lookup suffixes to components.

Call sites no longer inspect locales, choose plural categories, construct lookup keys, or assemble grammatical fragments. AnimatedCountLabel still animates digits, but intentionally drops the English-specific noun-tail animation.

Phrase migration

All 62 UI dictionaries replace:

  • ui.lineComment.label.prefix + .suffix with ui.lineComment.label: "...{{selection}}..."
  • ui.lineComment.editorLabel.prefix + .suffix with ui.lineComment.editorLabel: "...{{selection}}..."
  • ui.list.emptyWithFilter.prefix + .suffix with ui.list.emptyWithFilter: "...{{query}}..."

A mechanical verification compared every new template with origin/dev and proved it equals the old prefix + typed slot + suffix byte-for-byte. Japanese/Korean suffix order and Chinese surrounding text remain dictionary-controlled. Parity tests require every rich key to contain exactly one expected slot and reject all legacy fragment keys.

Translation research

The retained-English review used repository terminology plus Unicode CLDR script identity, Firefox/Pontoon, KDE localization, and official/local public-sector terminology where maintained corpora were unavailable.

  • Bengali: ওয়েব অনুসন্ধান
  • Dzongkha: ཡོངས་འབྲེལ་འཚོལ་ཞིབ།
  • Nepali: वेब खोज
  • Shahmukhi Punjabi, matching the repository's current pa dictionary: ویب تلاش
  • Sinhala: වෙබ් සෙවුම

{{provider}} is preserved exactly. Sinhala Render becomes the dictionary’s existing rendering term, විදැහුම්.

Sources included Mozilla Firefox/Pontoon, KDE translation memory, CLDR likely-subtag data, the Dzongkha Development Commission, and repository-local prior art. The broader standards mismatch where bare pa normally implies Gurmukhi while this repository’s dictionary is Shahmukhi remains outside this focused fix.

Checks

  • CI=true bun test ./src/i18n/parity.test.ts ./src/i18n/desktop-native.test.ts from packages/app
  • bun test ./src/context/i18n.test.ts from packages/ui
  • bun typecheck from packages/app, packages/ui, packages/session-ui, and packages/enterprise
  • scoped oxlint — 0 errors
  • Prettier check across every changed file
  • git diff --check
  • mechanical 62-dictionary rich-template equivalence verification
  • invariant scan: no session UI plural-category/key construction, no feature-level English locale branch, no legacy prefix/suffix keys, and no targeted retained-English values

Requested by: @Hona (Hona via Slack)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant