'sr' Plural rule is wrong
vicb opened this issue · comments
Not sure if it's because of bad CLDR data or code:
// > cldr.extractPluralRuleFunction('sr').toString()
function anonymous(n\n /**/) {
var i = Math.floor(Math.abs(n)), v = n.toString().replace(/^[^.]*\\.?/, '').length,
f = parseInt(n.toString().replace(/^[^.]*\\.?/, ''), 10) || 0;
if (typeof n === 'string') n = parseInt(n, 10);
if (v === 0 && i % 10 === 1 && (!(i % 100 === 11) || f % 10 === 1 && !(f % 100 === 11)))
return 'one';
if (v === 0 && i % 10 === Math.floor(i % 10) && i % 10 >= 2 && i % 10 <= 4 &&
(!(i % 100 >= 12 && i % 100 <= 14) ||
f % 10 === Math.floor(f % 10) && f % 10 >= 2 && f % 10 <= 4 &&
!(f % 100 >= 12 && f % 100 <= 14)))
return 'few';
return 'other'
}
'one' condition should be:
// || should be at top level
(v === 0 && i % 10 === 1 && (!(i % 100 === 11)) || f % 10 === 1 && !(f % 100 === 11))
'few' condition should be:
if (v === 0 && i % 10 === Math.floor(i % 10) && i % 10 >= 2 && i % 10 <= 4 &&
(!(i % 100 >= 12 && i % 100 <= 14)) ||
f % 10 === Math.floor(f % 10) && f % 10 >= 2 && f % 10 <= 4 &&
!(f % 100 >= 12 && f % 100 <= 14))
return Plural.Few;
Thanks for reporting this. Seems like I messed up the precedence of the "or" operator in the parser.
Should be fixed in 3.5.1, please reopen if not.
Thanks for the quick fix !
You're welcome :)