admin管理员组文章数量:1415139
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
1 Answer
Reset to default 4This 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
本文标签: javascripti18nextplural form incorrectStack Overflow
版权声明:本文标题:javascript - i18next - plural form incorrect - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745217076a2648221.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论