i18next - 复数形式不正确

时间:2014-08-14 12:50:37

标签: javascript jquery internationalization i18next

问题,我正在使用i18next,一切都很好,除了多个翻译。

多种翻译适用于某些语言,但不适用于其他语言。

例如,克罗地亚语不起作用。我添加了一些日志语句,看到它使用“name_plural_5”而不是使用翻译键“name_plural”..

这与这段代码有关:

        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
        }

参考了这个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);
            }
        },

供参考,英文如下:

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

现在有谁能告诉我这意味着什么?我是否需要为此语言提供多个复数翻译,为什么?

http://i18next.com

1 个答案:

答案 0 :(得分:3)

jamuhl (i18next的创建者)在GitHub上回答了这个问题:

  

并非每种语言都只有一个复数,例如。阿拉伯语已经超过6个。

     

多个定义来自:http://translate.sourceforge.net/wiki/l10n/pluralforms

     

对于定义复数的语言需要额外的数字,请参阅示例:https://github.com/jamuhl/i18next/blob/master/spec/translate/translate.plurals.spec.js#L96

- &GT; https://github.com/i18next/i18next/issues/292