feat: adds option for CLDR plurals in gettext
Description
Gettext has its own plural rules that are many times different than CLDR plurals. See gettext plurals and CLDR plurals
This option is helpful if you need to use CLDR plurals, but also have gettext style PO files.
In my case, my TMS does not support ICU in PO, but also uses CLDR plurals and not gettext plurals.
Types of changes
- [ ] Bugfix (non-breaking change which fixes an issue)
- [X] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [X] Documentation update
- [ ] Examples update
Checklist
- [X] I have read the CONTRIBUTING and CODE_OF_CONDUCT docs
- [X] I have added tests that prove my fix is effective or that my feature works
- [X] I have added the necessary documentation (if appropriate)
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| js-lingui | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Aug 19, 2024 3:15pm |
Example issue:
Czech in gettext has 3 plural forms, but CLDR defines 4. If you have a translation entry like this one below, the default gettext formatter will fail.
msgid ""
msgstr ""
"Language: cs\n"
#. js-lingui:icu=%7Bcount%2C+plural%2C+one+%7B%7Bcount%7D+day%7D+few+%7B%7Bcount%7D+days%7D+many+%7B%7Bcount%7D+days%7D+other+%7B%7Bcount%7D+days%7D%7D&pluralize_on=#
msgid "# day"
msgid_plural "# days"
msgstr[0] "# den"
msgstr[1] "# dny"
msgstr[2] "# dne"
msgstr[3] "# dní"
And it will be incorrectly parsed into:
{#, plural, one {# den} few {# dny} other {# dne} undefined {# dní}}
But with this new option set, it will correctly create:
{#, plural, one {# den} few {# dny} many {# dne} other {# dní}}
size-limit report 📦
| Path | Size |
|---|---|
| ./packages/core/dist/index.mjs | 2.88 KB (0%) |
| ./packages/detect-locale/dist/index.mjs | 723 B (0%) |
| ./packages/react/dist/index.mjs | 1.67 KB (0%) |
| ./packages/remote-loader/dist/index.mjs | 7.26 KB (0%) |