feat: i18n infrastructure + en/zh-CN translations + per-locale demos#9
Merged
feat: i18n infrastructure + en/zh-CN translations + per-locale demos#9
Conversation
Ships an i18next-backed translation layer with two locales (English and Simplified Chinese), a normalize/detect helper that coalesces zh-Hans* variants, and a missing-key warner that surfaces gaps as visible markers in dev. No silent fallbacks. Signed-off-by: hqhq1025 <1506751656@qq.com>
Splits the four built-in demos into ./locales/en.ts and ./locales/zh-CN.ts and exposes locale-aware getDemos() / getDemo(). BUILTIN_DEMOS is kept as an English alias so renderer code that has not migrated yet keeps working. Signed-off-by: hqhq1025 <1506751656@qq.com>
Adds registerLocaleIpc() exposing locale:get-system, locale:get-current, and locale:set. Persists user choice to ~/.config/open-codesign/locale.json with a schemaVersion field — separate from config.toml so i18n can boot before the encrypted config loader finishes. Renderer wiring is deferred to the maintainer because apps/desktop/src/main/index.ts and the preload bridge are owned by the parallel preview-ux-v2 branch. Signed-off-by: hqhq1025 <1506751656@qq.com>
Signed-off-by: hqhq1025 <1506751656@qq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal
Land the i18n substrate so the app can ship in English and Simplified Chinese without any further infrastructure work. Strings, demos, and the main-process locale IPC are all in place. Renderer wiring (App.tsx, store, preload) is intentionally not in this PR — those files are owned by the parallel
wt/preview-ux-v2branch and will be hooked up by the maintainer in a follow-up integration commit.This is the rebuilt successor to the abandoned
wt/i18nbranch: same substance, clean diff against today'smain, zero touches to renderer files.Files in
packages/i18n/package.json+tsconfig.json@open-codesign/i18npackages/i18n/src/index.tsinitI18n/setLocale/useT/normalizeLocale/isSupportedLocale/availableLocales/getCurrentLocalepackages/i18n/src/locales/{en,zh-CN}.jsoncommon,preview,chat,settings,onboarding,commands,errors,demospackages/i18n/src/i18n.test.tspackages/templates/src/locales/{en,zh-CN}.tsDemoTemplate[]for the four built-in demospackages/templates/src/index.tsgetDemos(locale)/getDemo(id, locale).BUILTIN_DEMOSretained as English alias for back-compat.packages/templates/package.json@open-codesign/i18nworkspace depapps/desktop/src/main/locale-ipc.tsregisterLocaleIpc()exposinglocale:get-system,locale:get-current,locale:set— persists to~/.config/open-codesign/locale.json(separate fromconfig.toml, withschemaVersion: 1)docs/I18N.mdFiles out (parallel-worktree boundary — NOT touched)
apps/desktop/src/main/index.tsapps/desktop/src/preload/index.tsapps/desktop/src/renderer/src/App.tsxapps/desktop/src/renderer/src/store.tsapps/desktop/src/renderer/src/main.tsxapps/desktop/src/renderer/src/onboarding/**apps/desktop/src/renderer/src/components/**New production dependencies
i18nextreact-i18nextuseTranslationhook) for i18nextBoth are MIT, Apache-2.0 compatible, zero transitive bloat. Combined raw cost: < 80 KB. Well inside the §1 lean budget. No alternatives considered seriously:
react-intlis ~3x the size, hand-rolling means re-implementing pluralization rules.Hard rules respected
console.warn(key, namespace, locale)and render as\u27E6key\u27E7in dev so they jump out in the UI.schemaVersion: 1.any, bracket notation,import typefor type-only imports.initI18n(locale); resources are inlined JSON, no async fetch.Integration notes for the maintainer
After
wt/preview-ux-v2lands, wire up the renderer in a single follow-up commit. Three steps:1. Main process —
apps/desktop/src/main/index.ts2. Preload —
apps/desktop/src/preload/index.tsAdd to the bridged API:
3. Renderer —
apps/desktop/src/renderer/src/main.tsx4.
t(...)migration tableReplace each hard-coded string in App.tsx, onboarding, and components with the matching key. Use
const t = useT()at the top of each component.'pre-alpha'chipt('common.preAlpha')'BYOK · local-first · multi-model't('common.tagline')'Send'buttont('common.send')t('settings.title'),t('settings.tabs.models'), etc.t('onboarding.welcome.title')t('onboarding.welcome.subtitle')t('onboarding.welcome.{tryFree,useKey,useOllama}')t('onboarding.paste.{title,placeholder}')t('onboarding.paste.recognized', { provider })t('onboarding.paste.connected', { count })t('onboarding.paste.advanced.{title,description}')t('onboarding.paste.errors.{401,402,429,network}')t('onboarding.choose.{title,primary,fast,start}'),t('onboarding.choose.estimatedCost', { amount })t('preview.empty.{title,body,starterChip}')t('preview.loading.title')t('preview.error.{title,body,copyError}')t('chat.placeholder')t('chat.sendShortcut')t('commands.{title,placeholder}'),t('commands.items.{newDesign,toggleTheme,openSettings,export}')t('errors.generic')/t('errors.providerError', { message })/t('errors.providerAuthMissing')For demos, swap
BUILTIN_DEMOSimport togetDemos(currentLocale)(and have the store holdcurrentLocale). TheBUILTIN_DEMOSalias stays in place during migration so nothing breaks mid-flight.5. Settings → Language dropdown
Three options: System default (passes
undefinedsonormalizeLocalefalls back toapp.getLocale()), English, 中文. On change:await window.electronAPI.locale.set(value); await setLocale(value);and re-render.§5b checklist
BUILTIN_DEMOSalias kept; new IPC channels are net-additive; locale file is schema-versioned.availableLocalesentry). Documented indocs/I18N.md.Verification