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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745217076a4617075.html
评论列表(0条)