Skip to content

fix(i18n): Select plural forms by key instead of position - #2757

Open
krish-goradia wants to merge 1 commit into
wxt-dev:mainfrom
krish-goradia:fix/i18n-plural-keys
Open

krish-goradia wants to merge 1 commit into
wxt-dev:mainfrom
krish-goradia:fix/i18n-plural-keys

Conversation

@krish-goradia

Copy link
Copy Markdown

Overview

  • Bug: A YAML file with only 0: and n and when this runs : t('items', 1) returns the "0" text while t('items', 0) returns "0 items" A numeric group like errors: {404: ..., 500: ...} became one plural, so t('errors.404') returned empty
  • Cause: the build saves the plural forms joined by | without their keys and at runtime t() decides which form is which by counting them
  • Fix: forms always saved in the order zero | one | n (missing ones filled from n and objects without n aren't plurals whileother keys throw an error
  • Unchanged: the output for {n}, {1,n} and {0,1,n} is exactly the same

Manual Testing

  • Testing: I ran the i18n tests (including the new plural.test.ts): 60/60 pass, 6 fail without the fix

Related Issue

One reference was from Refs #2747 (point 1)

Plurals were serialized with `Object.values(...).join(' | ')`, but the
runtime picks a form by position, so `{ 0, n }` returned the zero form for
a count of 1, and `{ 1, 2, n }` was read as `{ 0, 1, n }`. Objects with
only numeric keys, like `{ 404: ..., 500: ... }`, were also collapsed into
one plural message instead of nested messages.

- Serialize plurals as `one | n` or `zero | one | n`, falling back to `n`
  for a missing form. Output for `{ n }`, `{ 1, n }` and `{ 0, 1, n }` is
  unchanged.
- Only treat objects with an `n` key as plurals.
- Throw a clear error for plural keys other than 0, 1 and n.

Refs wxt-dev#2747

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@netlify

netlify Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for creative-fairy-df92c4 ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit c534930
🔍 Latest deploy log https://app.netlify.com/projects/creative-fairy-df92c4/deploys/6afa397a4d21eb2ae34bbfa4
😎 Deploy Preview https://deploy-preview-2757--creative-fairy-df92c4.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Nov 15, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

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: 95f347a4-b494-4534-b8e0-2c48da9de1ae

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • 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

@github-actions github-actions Bot added the pkg/i18n Includes changes to the `packages/i18n` directory label Nov 15, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg/i18n Includes changes to the `packages/i18n` directory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant