NGettext
NGettext copied to clipboard
Plural translation wrong
ICatalog catalog = new Catalog("lv", "./locale", new CultureInfo("lv"));
Console.WriteLine(catalog.GetString("My name is {0}"), "Enzo");
int i = 0;
Console.WriteLine(catalog.GetPluralString("I'm {0} year old.", "I'm {0} years old.", i), i);
i = 21;
Console.WriteLine(catalog.GetPluralString("I'm {0} year old.", "I'm {0} years old.", i), i);
i = 22;
Console.WriteLine(catalog.GetPluralString("I'm {0} year old.", "I'm {0} years old.", i), i);
Those are translated to latvian which has (nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2);)
using Poedit.
Console prints: (in paranthesis I have added from which translation it comes)
Mani sauc Enzo Man ir 0 gads. (n -> 1, 21, 31, 41 translation) Man ir 21 gadu. (n -> 2, 3, 4, 5.. translation) Man ir 22 gadu. (Zero translation)
I really don't care about '0' case, because that's the first time I hear my native language has 3 types of those, but anyway, they are all wrong! xgettext prints this correctly.
Where did you get that plural form expression? By default, NGettext uses precompiled plural formulas and for the "lv" locale it looks different:
(n == 0) ? 0 : (((n % 10 == 1) && (n % 100 != 11)) ? 1 : 2)
You can correct your poedit formula or enable plural formula reader to read it from your mo file.
It is Poedit's default. The same as you can find on http://docs.translatehouse.org/projects/localization-guide/en/latest/l10n/pluralforms.html?id=l10n/pluralforms
You can correct your poedit formula or enable plural formula reader to read it from your mo file.
You mean like this?
ICatalog catalog = new Catalog(new MoCompilingPluralLoader("Example", "./locale"));
If so, I didn't find a way to specify CultureInfo.
NGettext uses the Unicode CLDR project data for plural form formula generation. But now it's outdated (see issue #4). And still, cldr provides formula different from yours. Form with 0 index is used for 0-type values, index 1 — for numhers ending with 1, and index 2 for others. If you want, you can suggest different plural form expression provider so I can use it for generation of precompiled plural forms.
If so, I didn't find a way to specify CultureInfo.
It's the second parameter of the Catalog constructor in your case.
Thanks!