javascript - i18next - plural form incorrect - Stack Overflow

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

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?

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.

Share Improve this question asked Aug 14, 2014 at 12:50 user429620user429620 1
  • Have you tried using l10ns? It handles your plurals with ICU's plural format. Which is much simpler. – einstein Commented Oct 21, 2014 at 0:31
Add a ment  | 

1 Answer 1

Reset to default 4

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/wiki/l10n/pluralforms

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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745217076a4617075.html

相关推荐

  • javascript - i18next - plural form incorrect - Stack Overflow

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

    3小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信