You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are currently in the process of converting the localization of our application from 2-letter ISO Codes to 4-letter ISO Codes, and we use lingui for localizing all of our front-end applications.
We renamed all of PO files (messages.en.po -> messages.en-CA.po), and changed our lingui.config.tslocales from en to en-CA.
For the PO files content, following the GNU Documents, the Language header can be in the following format;
‘ll_CC’, where ‘ll’ is an ISO 639 two-letter language code (lowercase) and ‘CC’ is an ISO 3166 two-letter country code (uppercase).
So we changed the Language header from en to en_CA.
Describe the bug
After changing the Language header in the PO files, the plurals couldn't be parsed correctly by @lingui/loader. We got the following error message: Multiple translations for item with key KEY in language en_CA, but no plural cases were found. This prohibits the translation of .po plurals into ICU plurals. Pluralization will not work for this key.
We pinpointed the error to the getPluralCases(lang) called by convertPluralsToICU(items, lang) method in packages/cli/src/api/formats/po-gettext.ts. It seems like it's using the language from the PO file header as-is, and node-gettext/lib/plurals doesn't have any country-coded language code. Therefore, no plural cases are ever found.
I was able to "fix" this issue by adding these couple of lines at the beginning of getPluralCases(lang):
But I am curious if it's a configuration issue on our side. I couldn't find anything in the docs explaining how to handle such a use-case (country-coded language codes + po-gettext format + plurals), but maybe there's an undocumented way of doing it?
To Reproduce
Using a PO file with a country-coded language code such as:
We are currently in the process of converting the localization of our application from 2-letter ISO Codes to 4-letter ISO Codes, and we use lingui for localizing all of our front-end applications.
We renamed all of PO files (
messages.en.po
->messages.en-CA.po
), and changed ourlingui.config.ts
locales
fromen
toen-CA
.For the PO files content, following the GNU Documents, the
Language
header can be in the following format;So we changed the
Language
header fromen
toen_CA
.Describe the bug
After changing the
Language
header in the PO files, the plurals couldn't be parsed correctly by@lingui/loader
. We got the following error message:Multiple translations for item with key KEY in language en_CA, but no plural cases were found. This prohibits the translation of .po plurals into ICU plurals. Pluralization will not work for this key.
We pinpointed the error to the
getPluralCases(lang)
called byconvertPluralsToICU(items, lang)
method inpackages/cli/src/api/formats/po-gettext.ts
. It seems like it's using the language from the PO file header as-is, andnode-gettext/lib/plurals
doesn't have any country-coded language code. Therefore, no plural cases are ever found.I was able to "fix" this issue by adding these couple of lines at the beginning of
getPluralCases(lang)
:But I am curious if it's a configuration issue on our side. I couldn't find anything in the docs explaining how to handle such a use-case (country-coded language codes + po-gettext format + plurals), but maybe there's an undocumented way of doing it?
To Reproduce
Using a PO file with a country-coded language code such as:
and a country-coded language code in your
lingui.config.ts
, such as:You can simply run
lingui compile
and it should reproduce the error.Expected behavior
It should find the correct plural cases for country-coded language codes, such as "en-CA" or "fr-CA".
The text was updated successfully, but these errors were encountered: