问题,我正在使用 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);
}
},
谁能告诉我这是什么意思?我是否需要为这种语言提供多种复数翻译,为什么?
最佳答案
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
关于javascript - i18next - 复数形式不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25308485/