Add support for Russian plurals
String given as "0 items | items ending with 1 (except 11) | items ending 2-4 (except 12-14) | other" or without the 0 option as "items ending with 1 (except 11) | items ending 2-4 (except 12-14) | other".
This commit is contained in:
parent
d7a28f511b
commit
cae78e860f
2 changed files with 41 additions and 11 deletions
|
|
@ -20,5 +20,35 @@ export default new VueI18n({
|
|||
locale: 'en',
|
||||
fallbackLocale: 'en',
|
||||
silentFallbackWarn: true,
|
||||
messages: messages
|
||||
messages: messages,
|
||||
pluralizationRules: {
|
||||
/**
|
||||
* @param choice {number} a choice index given by the input to $tc: `$tc('path.to.rule', choiceIndex)`
|
||||
* @param choicesLength {number} an overall amount of available choices
|
||||
* @returns a final choice index to select plural word by
|
||||
*/
|
||||
'ru': function(choice, choicesLength) {
|
||||
// this === VueI18n instance, so the locale property also exists here
|
||||
|
||||
if (choice === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const zeroChoiseOffset = (choicesLength == 4) ? 1 : 0;
|
||||
|
||||
const teen = choice > 10 && choice < 20;
|
||||
const endsWithOne = choice % 10 === 1;
|
||||
|
||||
if (!teen && endsWithOne) {
|
||||
console.log("Not teen, ends with one", zeroChoiseOffset, choice);
|
||||
return zeroChoiseOffset + 0;
|
||||
}
|
||||
if (!teen && choice % 10 >= 2 && choice % 10 <= 4) {
|
||||
console.log("Ends with 2-4", zeroChoiseOffset, choice);
|
||||
return zeroChoiseOffset + 1;
|
||||
}
|
||||
console.log("Other", choice);
|
||||
return (choicesLength < 4) ? 2 : 3;
|
||||
}
|
||||
}
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue