Skip to content

Instantly share code, notes, and snippets.

@santhoshtr
Created May 24, 2014 10:03
Show Gist options
  • Save santhoshtr/2105e20977fdb6fc0d2f to your computer and use it in GitHub Desktop.
Save santhoshtr/2105e20977fdb6fc0d2f to your computer and use it in GitHub Desktop.
CLDR Plural rules converted to javascript function
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