-
Notifications
You must be signed in to change notification settings - Fork 387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(format-po-gettext): respect Plural-Forms header #2010
feat(format-po-gettext): respect Plural-Forms header #2010
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
size-limit report 📦
|
Might have to warn or hard error on msgid ""
msgstr ""
"Language: fr\\n"
"Plural-Forms: nplurals=3; plural=(n == 0 || n == 1) ? 0 : n != 0 && n % 1000000 == 0 ? 1 : 2;\\n"
#. js-lingui:icu=%7B0%2C+plural%2C+one+%7B%7Bcount%7D+day%7D+other+%7B%7Bcount%7D+days%7D%7D&pluralize_on=0
msgid "{count} day"
msgid_plural "{count} days"
msgstr[0] "{count} jour"
msgstr[1] "{count} jours" will result in runtime errors:
|
Also some uncaught runtime errors if the locale isn't found in the cldr plurals lib. Probably needs a cleaner error message, and also specifically for
|
@garikkh could you take it over and finish this PR? |
Most likely I will have some time this week to take over this PR. |
Had a few fixes here: timofei-iatsenko/js-lingui@feature/respect-plural-forms-header...garikkh:js-lingui:feature/respect-plural-forms-header tested the PO files my TMS generates, looks good. One thing to note is that because the library uses Another note: I considered using either https://www.npmjs.com/package/cldr or https://www.npmjs.com/package/cldr-data instead of having to copy/paste a json file, but both were just as silly to use for this case. Do you want me to make a new PR to lingui or to your branch? |
@timofei-iatsenko @garikkh is there anything we can do to help move this PR forward?
💯 I also feel that committing these rules in raw format might not be the best approach. It might be more efficient and manageable to use a dependency for this instead. |
@andrii-bodnar I linked a PR I made with @timofei-iatsenko fork as the base branch, just so it was a tiny bit neater. Wasn't sure if you guys wanted a separate PR.
Agreed but the one being used here doesn't export the JSON and the maintainer doesn't want to add it to their exports. I don't remember the exact issues with the other two, so I could check again. |
More details: cldr-data is a great repository, but the plurals data is difficult to parse. each language has plurals defined like this: "cs": {
"pluralRule-count-one": "i = 1 and v = 0 @integer 1",
"pluralRule-count-few": "i = 2..4 and v = 0 @integer 2~4",
"pluralRule-count-many": "v != 0 @decimal 0.0~1.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …",
"pluralRule-count-other": " @integer 0, 5~19, 100, 1000, 10000, 100000, 1000000, …"
}, And not exactly great to parse and extract actual samples from.
> cldr.extractPluralClasses("cs")
[ 'one', 'few', 'many', 'other' ]
> cldr.extractPluralRuleFunction("cs")(1)
'one'
> cldr.extractPluralRuleFunction("cs")(100)
'other' But other than that only provides raw xml for data: <pluralRules locales="cs sk">
<pluralRule count="one">i = 1 and v = 0 @integer 1</pluralRule>
<pluralRule count="few">i = 2..4 and v = 0 @integer 2~4</pluralRule>
<pluralRule count="many">v != 0 @decimal 0.0~1.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …</pluralRule>
<pluralRule count="other"> @integer 0, 5~19, 100, 1000, 10000, 100000, 1000000, …</pluralRule>
</pluralRules> And for the forms: <pluralRanges locales="cs pl sk">
<pluralRange start="one" end="few" result="few"/>
<pluralRange start="one" end="many" result="many"/>
<pluralRange start="one" end="other" result="other"/>
<pluralRange start="few" end="few" result="few"/>
<pluralRange start="few" end="many" result="many"/>
<pluralRange start="few" end="other" result="other"/>
<pluralRange start="many" end="one" result="one"/>
<pluralRange start="many" end="few" result="few"/>
<pluralRange start="many" end="many" result="many"/>
<pluralRange start="many" end="other" result="other"/>
<pluralRange start="other" end="one" result="one"/>
<pluralRange start="other" end="few" result="few"/>
<pluralRange start="other" end="many" result="many"/>
<pluralRange start="other" end="other" result="other"/>
</pluralRanges> |
Description
Types of changes
Fixes # (issue)
Checklist