Created
May 24, 2014 10:03
-
-
Save santhoshtr/2105e20977fdb6fc0d2f to your computer and use it in GitHub Desktop.
CLDR Plural rules converted to javascript function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PluralRules.rules = { | |
"keys": ["one", "few", "many", "other"], | |
"rule": function (n) { | |
return (function () { | |
if (n % 10 == 1 && !(n % 100 == 11)) { | |
return "one" | |
} else { | |
return (function () { | |
if ([2, 3, 4].indexOf(n % 10) >= 0 && !([12, 13, 14].indexOf(n % 100) >= 0)) { | |
return "few" | |
} else { | |
return (function () { | |
if (n % 10 == 0 || [5, 6, 7, 8, 9].indexOf(n % 10) >= 0 || [11, 12, 13, 14].indexOf(n % 100) >= 0) { | |
return "many" | |
} else { | |
return "other" | |
} | |
})(); | |
} | |
})(); | |
} | |
})(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment