lingui / lingui/js-lingui

PO Gettext extract does not generate correct plural placeholders

Open
#2,345 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
5.9k
Forks
457
Avg merge
1d 23h
Merged PRs (30d)
16

Description

### Description

When running `lingui extract` with locales that have different plural rules, we would expect the PO to have the correct number of `msgstr` for the number of plurals, but instead it just uses two (source locale, not even source code. Even if your source code has `zero, one, many` it will only put `msgstr[0], msgstr[1]`

### Verifications

- [x] I've checked [the docs](https://lingui.dev) and this isn't covered there.
- [x] I've searched existing issues on [GitHub](https://github.com/lingui/js-lingui/issues).

### Reproduction Steps

Add any plural

```tsx




{plural(count, {
one: "one book",
other: "many books",
})}

```

And use `ru` in locales - good example, as it has 4 plural forms, and rule is:
```
"Plural-Forms: nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n%100>=11 && n%100<=14)? 2 : 3);\n"
```

### Expected Behavior

Expect to see:

```po
#. js-lingui:icu=%7Bcount%2C+plural%2C+one+%7BThere%27s+one+book%7D+other+%7BThere+are+%23+books%7D%7D&pluralize_on=count
#: src/App.tsx:52
msgid "There's one book"
msgid_plural "There are # books"
msgstr[0] ""
msgstr[1] ""
msgstr[2] ""
msgstr[3] ""
```

Instead only get

```po
#. js-lingui:icu=%7Bcount%2C+plural%2C+one+%7BThere%27s+one+book%7D+other+%7BThere+are+%23+books%7D%7D&pluralize_on=count
#: src/App.tsx:52
msgid "There's one book"
msgid_plural "There are # books"
msgstr[0] ""
msgstr[1] ""
```

### Macro Support

Babel with babel-macro-plugin

### Lingui Version

5.5.1

### Babel Version

_No response_

### Framework

_No response_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with `lingui extract`, the provided plural examples, and the `ru` locale. Trace how plural metadata becomes PO `msgstr` entries; done means the generated PO contains four empty plural translations matching the locale's plural rules instead of two.

Written by the indexing model from the issue text.

Assessment

Tech stack
babel, react, typescript
Domain
cli, internationalization, localization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.