Repository navigation
fix(i18n): native plural rules for plugin packs in main; eager main i18n init - #35403
Conversation
- Plugin pack i18next resource IDs become BCP-47 private-use tags on the pack's base locale (ru-RU-x-orcapk-...), so Intl and i18next pick the pack's plural rules natively in main and renderer. Drops the renderer pluralResolver.getRule patch; pack registration is shared. Persisted uiLanguage and pack ids keep the plugin: form. - returnEmptyString: false in both instances; main no longer returns the raw uninterpolated fallback for an empty translation. - Main i18n initializes at module load (synchronous with in-memory resources), removing the initialized flag and interpolateFallback.
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryPlugin packs now use locale-based private-use tags so main and renderer can use native plural rules.
No actionable issues were found. Tests were inspected, not run. Reviews (1) · Last reviewed commit: "fix(i18n): native plural rules for plugi..." · Reviewed by Greptile |
|
No actionable comments were generated in the recent review.
|
ELI5
Plugin language packs now use the correct plural forms in native menus and dialogs, and the main process translation setup is simpler and correct before startup completes.
What Changed
plugin<hex>language. i18next can't derive plural rules from that, so it usedcount === 1 ? one : other. The renderer worked around this with apluralResolver.getRulemonkeypatch and a few/many fill; main had neither, so e.g. a Russian pack gave21 → otherand3 → otherin native dialogs (local-build-switch.ts).ru-RU-x-orcapk-<utf8 hex in 8-char subtags>. Intl and i18next pick the right rules natively (1→one, 3→few, 5→many, 21→one). The encoding is fixed-width, so IDs can't collide. A locale that Intl doesn't support falls back toen, as the old patch did.getRulemonkeypatch is deleted. Pack registration (remove the old bundles, fill few/many from_other, add the new ones) lives insrc/shared/plugins/plugin-language-pack-i18n-resources.tsand is used by both main and renderer.uiLanguage(plugin:<id>) and the packidare unchanged.resourceLanguagetravels only over main → its own renderer IPC (plugins:listLanguagePacks, same build), never to remote or mobile clients.load: 'currentOnly', the hierarchy stays[pack, en], so no built-in base-language catalog mixes in. zh-Hant behavior is unchanged.returnEmptyString: falseis set in both instances. Main's manual guard is removed; it returned the rawfallbackwith{{count}}still in it. An empty catalog value now resolves to the interpolated English fallback. No shipped catalog has empty values.initwith in-memory resources runs synchronously, so main now initializes at module load. Theinitializedflag,ensureMainI18n, and the duplicateinterpolateFallbackare deleted. Startup dialogs (main-process-preflight-failure.ts,prepareEarlyMainUiLanguage) translate and interpolate through i18next from the first call.Why
Native menus and dialogs used English plural rules for every plugin language pack. The eager init removes a second, partial interpolation path that existed only to cover the pre-init window.
Linked Issue
N/A (internal i18n audit follow-up)
Visual Proof
N/A: plural and fallback strings only; covered by unit tests.
Testing
New main test: a Russian plugin pack picks one/few/many(→other)/one for 1/3/5/21, and an empty pack value returns the interpolated fallback.
Updated the resource-ID expectations (artifact, registry, ProjectRoadmap). Removed the intl-locale test asserting that the old tag was Intl-invalid.
pnpm tc; 405 i18n/plugin-pack/startup-related test files;pnpm check:changed --maxWorkers=2.I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)