Skip to content

fix(i18n): native plural rules for plugin packs in main; eager main i18n init - #35403

Merged
OrcaWin merged 1 commit into
mainfrom
OrcaWin/i18n-audit-b
Oct 28, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
OrcaWin/i18n-audit-b

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​34 $\color{#cf222e}{\Huge{\mathbf{−}}}$​26 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​8
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​74 $\color{#cf222e}{\Huge{\mathbf{−}}}$​92 $\color{#cf222e}{\Huge{\mathbf{−}}}$​18

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

  1. Plugin pack plural rules in main. Plugin packs were registered in i18next under a synthetic plugin<hex> language. i18next can't derive plural rules from that, so it used count === 1 ? one : other. The renderer worked around this with a pluralResolver.getRule monkeypatch and a few/many fill; main had neither, so e.g. a Russian pack gave 21 → other and 3 → other in native dialogs (local-build-switch.ts).
    • Pack resource IDs are now BCP-47 private-use tags on the pack's base locale: 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 to en, as the old patch did.
    • The getRule monkeypatch is deleted. Pack registration (remove the old bundles, fill few/many from _other, add the new ones) lives in src/shared/plugins/plugin-language-pack-i18n-resources.ts and is used by both main and renderer.
    • Only the internal i18next resource ID changes. The persisted uiLanguage (plugin:<id>) and the pack id are unchanged. resourceLanguage travels only over main → its own renderer IPC (plugins:listLanguagePacks, same build), never to remote or mobile clients.
    • With load: 'currentOnly', the hierarchy stays [pack, en], so no built-in base-language catalog mixes in. zh-Hant behavior is unchanged.
  2. Empty translations. returnEmptyString: false is set in both instances. Main's manual guard is removed; it returned the raw fallback with {{count}} still in it. An empty catalog value now resolves to the interpolated English fallback. No shipped catalog has empty values.
  3. Eager main init. init with in-memory resources runs synchronously, so main now initializes at module load. The initialized flag, ensureMainI18n, and the duplicate interpolateFallback are 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

- 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.
@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Plugin packs now use locale-based private-use tags so main and renderer can use native plural rules.

  • Plugin packs use their own plural forms in native menus and dialogs.
  • Empty translations now show an interpolated English fallback.
  • Main startup dialogs translate from their first call.

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

@coderabbitai

coderabbitai Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cfea4c57-a4bc-453d-a811-bd60551b8a46
Commits

Reviewing files that changed from the base of the PR and between 93ff483 and c001309.

Files selected for processing: 12
  • src/main/i18n/main-i18n-lazy-locale.test.ts
  • src/main/i18n/main-i18n.ts
  • src/main/plugins/plugin-language-pack-registry.test.ts
  • src/main/startup/main-process-i18n-menu.ts
  • src/main/window/renderer-recovery-prompt.test.ts
  • src/renderer/src/components/github-project/ProjectRoadmap.test.tsx
  • src/renderer/src/i18n/i18n.ts
  • src/renderer/src/i18n/intl-locale.test.ts
  • src/renderer/src/i18n/weekday-names.ts
  • src/shared/plugins/plugin-language-pack-artifact.test.ts
  • src/shared/plugins/plugin-language-pack-artifact.ts
  • src/shared/plugins/plugin-language-pack-i18n-resources.ts
Files with no reviewable changes: 1
  • src/renderer/src/components/github-project/ProjectRoadmap.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Walkthrough

Plugin language pack resource IDs now use a supported locale base and private-use subtags. A shared helper replaces translation bundles and applies plural categories. Main-process i18n initializes at module load, and both main and renderer processes use the helper when plugin packs change. i18next treats empty translation values as missing. Tests cover Russian plural forms, empty-value fallback, and the updated resource ID format.

Priority: Normal

Merge Risk: Minimal · up to c0013

No issue requiring a fix before merge was established. The change is mergeable after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly summarizes the primary changes: native plural rules for plugin packs and eager main-process i18n initialization.
Description check Passed The description is structured and covers the change, rationale, testing, visual proof, compatibility considerations, and checklist. The Linked Issue section is marked N/A instead of providing an issue…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is structured and covers the change, rationale, testing, visual proof, compatibility considerations, and checklist. The Linked Issue section is marked N/A instead of providing an issue reference, but the remaining required information is substantially complete.

Full details: Docstring Coverage

Explanation

Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 8 functions across 11 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@OrcaWin
OrcaWin merged commit 95a83cc into main Oct 28, 2026
43 checks passed
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