Repository navigation
fix(i18n): resolve plugin-pack plurals with the pack's declared locale - #12505
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
Walkthrough
Pre-merge checks:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/renderer/src/i18n/plugin-plural-locale.ts (1)
4-18: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueShorten the module comment.
Keep one concise comment that states why plural resolution uses the declared locale while resource lookup uses the synthetic language. The current block restates implementation details.
As per coding guidelines, comments must be concise, limited to non-obvious information, and preferably one line.
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 2f7335c8-82a8-4867-a51e-e310e85db824
📥 Commits
Reviewing files that changed from the base of the PR and between 2548b81 and b20e09c533df4e6ce883f5541aa7ecd327a3f263.
📒 Files selected for processing (3)
src/renderer/src/i18n/i18n.tssrc/renderer/src/i18n/plugin-plural-locale.test.tssrc/renderer/src/i18n/plugin-plural-locale.ts
|
Addressed in 188ca64bb. Canonicalizing alone turned out not to be enough. So the declared tag is now canonicalized (underscores folded first, so a Tests cover both directions: |
188ca64 to
6e9e889
Compare
The manifest accepts any string as a pack's locale, so a pack can declare ru_RU, not_a_locale, or xx. Two silent failures follow. Intl rejects a malformed tag outright, and for a well-formed but unknown one it falls back to the host locale: the pack would then select plural forms by whichever language the user's machine runs, which is impossible to reproduce for its author. Canonicalize the declared tag before it reaches the resolver and keep it only when Intl.PluralRules actually has data for it. A slip like ru_RU still lands on ru-RU; anything unresolvable leaves the lookup empty, so the resolver stays on the synthetic tag and the pack degrades to i18next's default instead of borrowing the host's rules. Addresses the review note on stablyai#12505.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/i18n/pack-locale.ts (1)
1-14: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCondense the locale rationale comments.
Keep the non-obvious rationale in one short comment at each site.
src/renderer/src/i18n/pack-locale.ts#L1-L14: replace the multi-paragraph block with one sentence that states canonicalization occurs before caller-specific Intl support checks.src/renderer/src/i18n/intl-locale.test.ts#L1-L9: replace the multi-paragraph block with one sentence that states ICU support is stubbed for deterministic tests.As per coding guidelines, comments must be concise, limited to non-obvious information, and preferably one line.
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7a07260b-b824-4f64-b421-ffa85a191c0f
📥 Commits
Reviewing files that changed from the base of the PR and between 188ca64bb09f32d36999540ebe004f3982d3f7c3 and 6e9e88961e1b204a0ca2e1e31c798acc5c7ace2f.
📒 Files selected for processing (5)
src/renderer/src/i18n/i18n.tssrc/renderer/src/i18n/intl-locale.test.tssrc/renderer/src/i18n/pack-locale.tssrc/renderer/src/i18n/plugin-plural-locale.test.tssrc/renderer/src/i18n/plugin-plural-locale.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- src/renderer/src/i18n/i18n.ts
- src/renderer/src/i18n/plugin-plural-locale.ts
- src/renderer/src/i18n/plugin-plural-locale.test.ts
|
Scope note: while rebasing this branch onto current That fix and the shared |
6e9e889 to
e219481
Compare
|
@nwparker — this and #12533 have no reviewer, and the reason looks like a gap worth fixing rather than something to ping around each time.
If you agree the whole directory belongs to the same owner, one line does it: Happy to send that as a one-line PR if you'd rather have it in the queue than in a comment. On the two PRs themselves, both are green and the split is deliberate:
No rush on either — mainly flagging that the routing gap is what's keeping them invisible, not the content. |
|
Heads-up on the red check here, since it is misleading: the Run 34408566433 was created 9 Sep 21:44 and concluded
So the red mark carries no information about the code — but it does make these PRs look broken to anyone scanning the queue, which seemed worth stating explicitly rather than leaving to inference. What I can confirm locally for this branch at
That rebase resolved one conflict: upstream replaced the eagerly bundled English catalog with The one thing that would help: a single "Approve and run" on these four would let CI actually execute, and the checks would then say something real either way. If any of them is unwanted, closing it is just as useful to me — #13020 was closed as superseded by #13118 last month and that was the right call, no complaints from me. |
…e tools Plural forms. The catalog now carries `_few` and `_many` for the 18 plural families whose form i18next picks from a `count`: 36 entries. Orca resolves a pack's plurals with the two English forms today (stablyai/orca#12106), so nothing changes on screen; an i18next probe under the synthetic resource language gives the same output as before for every family. Under ru-RU the forms read "сохранены 2 ветки", "сохранено 5 веток", "сохранена 21 ветка", which is what users get the day stablyai/orca#12505 lands. The nine families where the component picks the suffixed key itself get no extra forms: nothing would read them. One of those, the Warp theme import limit, had an `_other` that was wrong for 21; it is now count-neutral like the rest. Tools. The build, the release check and a pack audit move from an untracked working directory into tools/. audit-pack.py is new and works on any Orca language pack: engine verdict, coverage, stale keys, placeholder drift, all against a release tag rather than main. The build accepts a `_few`/`_many` form only while its family lives in Orca's catalog; the string count and coverage leave those forms out. READMEs, checked against the v1.4.224 UI code: - the marketplace card is titled "Russian", from the plugin key, not "Русский"; - installing is not enabling: the Review plugin step was missing from all three install paths; - sources are added through Manage sources, and updates are fetched with Check for update; Orca does not announce them; - the catalog file is 1.4 MB, not 1 MB; - the coverage figure is of what a pack may translate, not of the whole catalog; - the Russian README names the buttons as they appear before the pack is active, and its term counts follow the release. 15,433 strings, unchanged, plus 36 extra plural forms.
Plugin language packs register under synthetic plugin<hex> resource languages, so i18next's plural resolver fell back to English rules and Russian/Polish/etc. packs never selected their _few/_many forms. Map each pack's resource language to its declared (Intl-supported) locale inside the plural resolver, and fill missing plural categories from the key's _other form so packs that only ship _one/_other stay in-language. Co-authored-by: Evgenii <[email protected]>
b9ecbaa to
5d9be21
Compare
ELI5
Words like "1 file" and "5 files" change form with the number, and every language has its own rules for this. Russian, for example, uses different words for 2 and for 5. Plugin language packs are stored under a made-up internal name, so the app couldn't tell which language's rules to apply and quietly used English rules. Now the app reads the language the pack says it is and uses that language's rules.
What Changed
Before: a plugin pack registers its catalog under a synthetic resource language (
plugin<hex>frompluginLanguageResourceId()). i18next can't buildIntl.PluralRulesfrom that tag, so it falls back to a two-form English rule. For aru-RUpack, counts[1, 2, 5, 21]resolved toone, other, other, other, so the pack's_few/_manykeys could never be reached. That fallback also skips i18next's rule cache, so every lookup threw and caught aRangeError.After: the same counts resolve to
one, few, many, one.How it works (
src/renderer/src/i18n/i18n.ts):pluralResolver.getRuleis wrapped once, when the module loads. The wrapper maps a pack's resource language to the pack's declared locale before i18next looks up the rule. Resource lookup still uses the synthetic tag, and the built-inen/es/ja/ko/zhlocales go through unchanged.setRendererPluginLanguagePacksrebuilds that map each time the packs change. The declared locale goes throughIntl.PluralRules.supportedLocalesOf, and a locale ICU doesn't support maps toen. That gives the same one/other result as today, but now it is cached. The rule cache is keyed by the real locale, so it never needs clearing._one/_other. Without extra handling, few/many counts would fall through to English. The registered copy of each catalog fills any missing<base>_<category>(from the locale'spluralCategories) with that key's_othertext, so the text stays in the pack's language. Keys the pack ships are never overwritten, and the input catalog is not mutated.supportedIntlLocale()is shared bygetIntlLocale(DateTimeFormat) and the plural map (PluralRules).isCatalogObjectis now exported fromplugin-language-pack-artifact.tsso the fill reuses it instead of reimplementing it.Why
Maintainers chose option (1) in #12106: route plural selection through the locale the pack declares. No catalog content can fix this while selection runs on the synthetic tag. This approach changes only the code passed to the resolver, so i18next still owns how plural forms are selected, and every call site that passes
countgets the fix without changes.plugin-pack-plurals.test.tsguards the dependency on i18next internals across upgrades.Tradeoffs:
_othertext for the missing forms. The text stays in the pack's language but may be the wrong grammatical form._otherbut no_onenow shows its_othertext for count 1 instead of the English_one.Linked Issue
Part of #12106. This fixes cause 2 (plugin packs never reach CLDR rules). Cause 1, the call sites that pick a form with
=== 1 ? … : …, is a separate follow-up.Visual Proof
N/A. There is no new UI. The change is in plural-form selection for plugin language packs, and tests verify it directly. On origin/main's sources, both committed tests and a wider probe fail: 7 of 9 tests covering Russian nested keys, Arabic zero/two/few/many, switching locales, ordinals and
_other-only packs. All 9 pass on this branch.Testing
Reproduced on origin/main: a
ru-RUpack withk_one/k_few/k_many/k_otherresolves counts[1,2,5,21]toone, other, other, other. On this branch it resolves toone, few, many, one.pnpm test src/renderer/src/i18n src/shared/plugins/plugin-language-pack-artifact: everything passes exceptlanguage-detection-reconciliation.test.tsx. That file hits a 60sbeforeEachtimeout and fails the same way on a clean origin/main checkout under the same machine load.oxlint, oxfmt --check, anti-slop oxlint, native code-quality oxlint, ast-grep, and
check-changed-code-quality.mjsare clean on the touched files.Tested on macOS. The change is pure JS (
Intlplus aMap) with no paths, IPC, or platform APIs. It touches only the renderer, so there is no SSH/remote, mobile, or folder-workspace impact.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Notes
No security, cross-platform, remote SSH, mobile, or backwards-compatibility impact. The pack locale comes from an already-validated manifest and is only passed to
Intl. Performance improves because plugin-pack plural lookups no longer throw on every call.Original fix by @smwbev in #12505.