javascript - i18next - 复数形式不正确

标签 javascript jquery internationalization i18next

问题,我正在使用 i18next,一切正常,除了复数翻译。

复数翻译适用于某些语言,但不适用于其他语言。

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

跟这段代码有关系:

        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

最佳答案

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

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

关于javascript - i18next - 复数形式不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25308485/

相关文章:

javascript - aws-lambda 找不到模块

sorting - Cakephp 3 分页器使用翻译行为 i18n 对字段进行排序

php - CakePHP 国际化

javascript - 为什么这些 promise 是同时执行的,而不是按顺序执行的?

javascript - 在苹果设备上运行的 Websockets 网络性能不佳

javascript - 如何确保我的 div 中的最后一个标记始终是 <br/>? IE11 中的插入符号问题(错误?)

jquery - 使用边界半径从左向右移动的 slider 不保持边界半径

qt - 如何为大型 Qt 项目生成单个翻译文件?

javascript - 我需要设置显示: block on div then find an anchor within that div

jQuery 和函数范围