js-lingui icon indicating copy to clipboard operation
js-lingui copied to clipboard

feat: adds option for CLDR plurals in gettext

Open garikkh opened this issue 1 year ago • 3 comments

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)

garikkh avatar Aug 19 '24 15:08 garikkh

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

vercel[bot] avatar Aug 19 '24 15:08 vercel[bot]

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í}}

garikkh avatar Aug 19 '24 15:08 garikkh

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%)

github-actions[bot] avatar Aug 19 '24 15:08 github-actions[bot]