angular-gettext icon indicating copy to clipboard operation
angular-gettext copied to clipboard

Bug in plural translations wrong language code

Open cojack opened this issue 9 years ago • 7 comments

If you translate strings to POSIX standard like: "en_US", "en_GB", "pl_PL" etc... Then you will never get an correct plural based on .po files. fe:

singular:

{{someone}} with {{somelese}} ({{duration}} minute)

plural:

{{someone}} with {{somelese}} ({{duration}} minutes)

In polish, it'll be:

{{someone}} z {{somelese}} ({{duration}} minuta) // form 0 {{someone}} z {{somelese}} ({{duration}} minuty) // form 1 {{someone}} z {{somelese}} ({{duration}} minut) // form 2

Then, when you translate it by poedit, you create an file with language: pl_PL in application I use pl_PL, and everytime i got form 1 or 0 if N is singular.

In the method getStringFormFor you should use

return plurals[gettextPlurals(gettextFallbackLanguage(language), n)];

or in gettextPlurals you should use fallback language.

Btw, @rubenv why you don't extract the plural form from .po files? Instead you creating your gettextPlurals factory?

cojack avatar Jun 06 '16 14:06 cojack

I have the same issue as I use en_US, fr_FR etc language codes.

The plural forms match is based on the first part of the code, the plural rules should be matched using the first part of the locale, like language.split('_')[0].

sinedied avatar Jun 16 '16 14:06 sinedied

@rubenv bump

cojack avatar Jun 17 '16 08:06 cojack

@rubenv why you don't extract the plural form from .po files? Instead you creating your gettextPlurals factory?

Because we don't want to include a parser for arbitrary expressions (or worse: eval).

I'd love to have this in, but it's not very high on our list of priorities right now on the project that I work on (we currently don't use sublanguage codes). Will gladly merge a patch for it though, just be sure to include a unit test.

rubenv avatar Jun 17 '16 08:06 rubenv

@cojack I've added simple fix for the issue could you update your angular-gettext to master or v2.3.1 and let me know if it fixes your problems?

IShotTheSheriff avatar Jun 20 '16 08:06 IShotTheSheriff

@IShotTheSheriff Thank you for your fix to support language codes with locale. But why was add support for format with separator ''_"? At this wiki page https://en.wikipedia.org/wiki/Language_code default separator is "-". And looks like it's the ISO standard.

Please, look and fix or add support for both language codes "en-US" and "en_US".

aprocom avatar Jun 29 '16 08:06 aprocom

@aprocom The convention when specifying locales in programming environments is an underscore, which you can verify by running locale on a unix machine:

$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
....

But yeah, it makes sense to support both versions, should be a trivial fix.

rubenv avatar Jun 29 '16 08:06 rubenv

@rubenv please look at pull request https://github.com/rubenv/angular-gettext/pull/309

aprocom avatar Aug 22 '16 13:08 aprocom