Skip to content

fix(i18n): show English Memory settings labels instead of Chinese fallback#246

Open
craigamcw wants to merge 1 commit into
OpenCoworkAI:mainfrom
craigamcw:fix/i18n-english-fallback-memory-settings
Open

fix(i18n): show English Memory settings labels instead of Chinese fallback#246
craigamcw wants to merge 1 commit into
OpenCoworkAI:mainfrom
craigamcw:fix/i18n-english-fallback-memory-settings

Conversation

@craigamcw

Copy link
Copy Markdown

Problem

When the app language resolves to English, several Memory settings labels still render in Chinese — e.g. 运行时配置 and 默认继承当前激活的 API 配置。这里主要调节导航深度、embedding 和落盘目录。.

Root cause: SettingsMemory.tsx calls t('memory.xxx', '<Chinese>') for ~37 keys, passing the Chinese string as i18next's default value (2nd arg). Those memory.* keys were never added to en.json (or zh.json), so i18next falls back to the inline Chinese for every language. The keys exist nowhere, so even zh was relying on the inline defaults.

This is the i18n anti-pattern the project's own src/renderer/i18n/README.md warns against ("避免硬编码 — 所有用户可见的文本都应该通过 t() 函数").

Fix

  • Add the missing memory.* keys to en.json (proper English) and zh.json (the strings that were previously hardcoded as defaults). The two locale key sets stay in sync, as the i18n README requires.
  • Drop the inline Chinese t() default arguments in SettingsMemory.tsx so the source uses t('key') only, matching the rest of the codebase. This also removes the latent trap where any future missing key silently reintroduces Chinese.
  • Remove dead Chinese fallbacks in SettingsPanel.tsx (settings.remote / settings.remoteDesc already existed in en.json, so English was already correct there — the inline Chinese was just redundant).
  • Localize the default config-set names (默认方案 / 配置方案 N) in useApiConfigState.ts via the i18n instance + two new api.* keys, so a fresh English install no longer shows a Chinese profile name.

Intentionally not touched: the 中文 native-language label in SettingsGeneral.tsx (correct as-is) and Chinese code comments (not user-visible).

Verification

  • tsc --noEmit — passes
  • eslint src on the changed files — 0 errors (2 pre-existing unrelated warnings)
  • prettier --check — clean
  • Renderer/config vitest suite — 89 tests pass (incl. the config-set builders and SettingsPanel entry tests)
  • Script check: all 123 i18n keys referenced by the changed files now resolve in both en.json and zh.json; the memory and api namespace key sets match between locales.

No behavior change for Chinese users (same strings, now sourced from zh.json); English users now get English.

…lish UI

SettingsMemory.tsx referenced ~37 memory.* i18n keys that were never added
to the locale files and passed Chinese strings as the t() default value.
With those keys missing from en.json, English users got the Chinese
fallbacks (e.g. "运行时配置", "默认继承当前激活的 API 配置…").

- Add the missing memory.* keys to en.json (English) and zh.json (the
  strings previously hardcoded as defaults), keeping both locale key sets
  in sync as the i18n README requires.
- Drop the inline Chinese t() default arguments so the source matches the
  project convention of t('key') only.
- Remove the now-dead Chinese fallbacks in SettingsPanel.tsx (those keys
  already existed in en.json, so English was already correct there).
- Localize the default config-set names ("默认方案" / "配置方案 N") in
  useApiConfigState via the i18n instance + new api.* keys.

typecheck, eslint, prettier and the renderer/config vitest suite all pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review mode: initial

Findings

  • [Minor] Potential i18n initialization timing risk in useApiConfigState.ts:434. The exported function buildApiConfigSets uses i18n.t() directly via module-level import. Although currently called only from within React component lifecycle (reducer initializer), if called before i18n is initialized (e.g., during module evaluation in tests or future refactors), it could throw or return a missing-key fallback. Consider passing the t function as a parameter to make the dependency explicit and safe for any caller.
    // Suggested approach: accept t as parameter
    export function buildApiConfigSets(
      options: BuildApiConfigSetsOptions,
      t: (key: string, options?: Record<string, unknown>) => string // pass t from useTranslation hook or i18n.t
    ): ApiConfigSet[] { ... }

Summary

No blockers or regressions. The change correctly moves hardcoded Chinese default strings into en.json and zh.json, eliminating the i18n anti-pattern where the Chinese string was used as the fallback for all languages. All keys referenced in the changed source files (SettingsMemory.tsx, SettingsPanel.tsx, useApiConfigState.ts) have been verified to exist in both locale files. The diff is clean and well-scoped. The risk described above is minor and exists only under hypothetical non-React usage; the current code works correctly.

Testing

Not run (automation). The PR states 89 tests pass. No new tests were added for the i18n key coverage, which is acceptable for a pure i18n refactor.

Open Cowork Bot

craigamcw added a commit to craigamcw/open-cowork that referenced this pull request Jun 16, 2026
- Fix the active-language highlight in SettingsGeneral: the old
  `startsWith('zh') ? 'zh' : 'en'` logic never matched the new languages.
  Normalize to the base code (es-ES -> es, zh-CN -> zh) and map Norwegian
  nb/nn -> the shipped `no` locale.
- Add nb/nn -> no fallback and `nonExplicitSupportedLngs` so browser region
  variants (e.g. es-ES, de-DE, nb-NO) resolve to the right locale.
- Restore the original Chinese comments in i18n/config.ts (only functional
  changes remain in the diff).
- Add memory.* and api.* keys to en.json/zh.json so all 12 locales share an
  identical key set (these mirror OpenCoworkAI#246).
- Add a Vitest key-parity test (src/tests/i18n/) asserting every locale has
  exactly the same keys as en.json, to catch future drift.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
cursor Bot pushed a commit to Emilien-Etadam/open-cowork that referenced this pull request Jun 23, 2026
Adds full UI translations for Spanish (es), French (fr), German (de),
Italian (it), Ukrainian (uk), Polish (pl), Swedish (sv), Norwegian (no),
Dutch (nl) and Romanian (ro), alongside the existing English and Chinese.

- New locale files under src/renderer/i18n/locales/ (all 866 keys, native
  orthography, interpolation placeholders preserved)
- Register the locales and extend supportedLngs in i18n/config.ts
- Add the languages to the Settings -> General language switcher

The browser/UI language detector already picks these up automatically.
Complements the Memory-settings English-fallback fix in OpenCoworkAI#246 (the new
locales include those keys).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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