Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

i18next - plural form incorrect

Question, I'm using i18next and all is well, except for plural translations.

Plural translations work great for some languages, but not for others.

For example, Croatian doesn't work. I added some log statements and saw that instead of using the translation key "name_plural" it uses "name_plural_5"..

It has something to do with this piece of code:

        var pluralKey = ns + o.nsseparator + key + o.pluralSuffix;
        var pluralExtension = pluralExtensions.get(lngs[0], options.count);
        if (pluralExtension >= 0) {
            pluralKey = pluralKey + '_' + pluralExtension;
        } else if (pluralExtension === 1) {
            pluralKey = ns + o.nsseparator + key; // singular
        }

Which references this pluralExtension:

            "hr": {
            "name": "Croatian",
            "numbers": [
                1,
                2,
                5
            ],
            "plurals": function(n) {
                return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
            }
        },

For reference, English looks like this:

        "en": {
            "name": "English",
            "numbers": [
                1,
                2
            ],
            "plurals": function(n) {
                return Number(n != 1);
            }
        },

Now can anyone tell me what this means? Do I need to supply multiple plural translations for this language, and why?

http://i18next.com


1 Answers

This question has been answered on GitHub by jamuhl (creator of i18next):

Not every language has just one plural for, eg. arabic has over 6.

Plural definitions are taken from: http://translate.sourceforge.net/wiki/l10n/pluralforms

For that language defining plurals need additional number, see sample: https://github.com/jamuhl/i18next/blob/master/spec/translate/translate.plurals.spec.js#L96

--> https://github.com/i18next/i18next/issues/292

like image 177
AndreM96 Avatar answered Nov 03 '25 22:11

AndreM96



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!