michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // This file is automatically generated with /python-lib/plural-rules-generator.py michael@0: // Fetching data from: http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml michael@0: michael@0: // Mapping of short locale name == to == > rule index in following list michael@0: michael@0: module.metadata = { michael@0: "stability": "unstable" michael@0: }; michael@0: michael@0: const LOCALES_TO_RULES = { michael@0: "af": 3, michael@0: "ak": 4, michael@0: "am": 4, michael@0: "ar": 1, michael@0: "asa": 3, michael@0: "az": 0, michael@0: "be": 11, michael@0: "bem": 3, michael@0: "bez": 3, michael@0: "bg": 3, michael@0: "bh": 4, michael@0: "bm": 0, michael@0: "bn": 3, michael@0: "bo": 0, michael@0: "br": 20, michael@0: "brx": 3, michael@0: "bs": 11, michael@0: "ca": 3, michael@0: "cgg": 3, michael@0: "chr": 3, michael@0: "cs": 12, michael@0: "cy": 17, michael@0: "da": 3, michael@0: "de": 3, michael@0: "dv": 3, michael@0: "dz": 0, michael@0: "ee": 3, michael@0: "el": 3, michael@0: "en": 3, michael@0: "eo": 3, michael@0: "es": 3, michael@0: "et": 3, michael@0: "eu": 3, michael@0: "fa": 0, michael@0: "ff": 5, michael@0: "fi": 3, michael@0: "fil": 4, michael@0: "fo": 3, michael@0: "fr": 5, michael@0: "fur": 3, michael@0: "fy": 3, michael@0: "ga": 8, michael@0: "gd": 24, michael@0: "gl": 3, michael@0: "gsw": 3, michael@0: "gu": 3, michael@0: "guw": 4, michael@0: "gv": 23, michael@0: "ha": 3, michael@0: "haw": 3, michael@0: "he": 2, michael@0: "hi": 4, michael@0: "hr": 11, michael@0: "hu": 0, michael@0: "id": 0, michael@0: "ig": 0, michael@0: "ii": 0, michael@0: "is": 3, michael@0: "it": 3, michael@0: "iu": 7, michael@0: "ja": 0, michael@0: "jmc": 3, michael@0: "jv": 0, michael@0: "ka": 0, michael@0: "kab": 5, michael@0: "kaj": 3, michael@0: "kcg": 3, michael@0: "kde": 0, michael@0: "kea": 0, michael@0: "kk": 3, michael@0: "kl": 3, michael@0: "km": 0, michael@0: "kn": 0, michael@0: "ko": 0, michael@0: "ksb": 3, michael@0: "ksh": 21, michael@0: "ku": 3, michael@0: "kw": 7, michael@0: "lag": 18, michael@0: "lb": 3, michael@0: "lg": 3, michael@0: "ln": 4, michael@0: "lo": 0, michael@0: "lt": 10, michael@0: "lv": 6, michael@0: "mas": 3, michael@0: "mg": 4, michael@0: "mk": 16, michael@0: "ml": 3, michael@0: "mn": 3, michael@0: "mo": 9, michael@0: "mr": 3, michael@0: "ms": 0, michael@0: "mt": 15, michael@0: "my": 0, michael@0: "nah": 3, michael@0: "naq": 7, michael@0: "nb": 3, michael@0: "nd": 3, michael@0: "ne": 3, michael@0: "nl": 3, michael@0: "nn": 3, michael@0: "no": 3, michael@0: "nr": 3, michael@0: "nso": 4, michael@0: "ny": 3, michael@0: "nyn": 3, michael@0: "om": 3, michael@0: "or": 3, michael@0: "pa": 3, michael@0: "pap": 3, michael@0: "pl": 13, michael@0: "ps": 3, michael@0: "pt": 3, michael@0: "rm": 3, michael@0: "ro": 9, michael@0: "rof": 3, michael@0: "ru": 11, michael@0: "rwk": 3, michael@0: "sah": 0, michael@0: "saq": 3, michael@0: "se": 7, michael@0: "seh": 3, michael@0: "ses": 0, michael@0: "sg": 0, michael@0: "sh": 11, michael@0: "shi": 19, michael@0: "sk": 12, michael@0: "sl": 14, michael@0: "sma": 7, michael@0: "smi": 7, michael@0: "smj": 7, michael@0: "smn": 7, michael@0: "sms": 7, michael@0: "sn": 3, michael@0: "so": 3, michael@0: "sq": 3, michael@0: "sr": 11, michael@0: "ss": 3, michael@0: "ssy": 3, michael@0: "st": 3, michael@0: "sv": 3, michael@0: "sw": 3, michael@0: "syr": 3, michael@0: "ta": 3, michael@0: "te": 3, michael@0: "teo": 3, michael@0: "th": 0, michael@0: "ti": 4, michael@0: "tig": 3, michael@0: "tk": 3, michael@0: "tl": 4, michael@0: "tn": 3, michael@0: "to": 0, michael@0: "tr": 0, michael@0: "ts": 3, michael@0: "tzm": 22, michael@0: "uk": 11, michael@0: "ur": 3, michael@0: "ve": 3, michael@0: "vi": 0, michael@0: "vun": 3, michael@0: "wa": 4, michael@0: "wae": 3, michael@0: "wo": 0, michael@0: "xh": 3, michael@0: "xog": 3, michael@0: "yo": 0, michael@0: "zh": 0, michael@0: "zu": 3 michael@0: }; michael@0: michael@0: // Utility functions for plural rules methods michael@0: function isIn(n, list) list.indexOf(n) !== -1; michael@0: function isBetween(n, start, end) start <= n && n <= end; michael@0: michael@0: // List of all plural rules methods, that maps an integer to the plural form name to use michael@0: const RULES = { michael@0: "0": function (n) { michael@0: michael@0: return "other" michael@0: }, michael@0: "1": function (n) { michael@0: if ((isBetween((n % 100), 3, 10))) michael@0: return "few"; michael@0: if (n == 0) michael@0: return "zero"; michael@0: if ((isBetween((n % 100), 11, 99))) michael@0: return "many"; michael@0: if (n == 2) michael@0: return "two"; michael@0: if (n == 1) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: "2": function (n) { michael@0: if (n != 0 && (n % 10) == 0) michael@0: return "many"; michael@0: if (n == 2) michael@0: return "two"; michael@0: if (n == 1) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: "3": function (n) { michael@0: if (n == 1) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: "4": function (n) { michael@0: if ((isBetween(n, 0, 1))) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: "5": function (n) { michael@0: if ((isBetween(n, 0, 2)) && n != 2) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: "6": function (n) { michael@0: if (n == 0) michael@0: return "zero"; michael@0: if ((n % 10) == 1 && (n % 100) != 11) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: "7": function (n) { michael@0: if (n == 2) michael@0: return "two"; michael@0: if (n == 1) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: "8": function (n) { michael@0: if ((isBetween(n, 3, 6))) michael@0: return "few"; michael@0: if ((isBetween(n, 7, 10))) michael@0: return "many"; michael@0: if (n == 2) michael@0: return "two"; michael@0: if (n == 1) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: "9": function (n) { michael@0: if (n == 0 || n != 1 && (isBetween((n % 100), 1, 19))) michael@0: return "few"; michael@0: if (n == 1) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: "10": function (n) { michael@0: if ((isBetween((n % 10), 2, 9)) && !(isBetween((n % 100), 11, 19))) michael@0: return "few"; michael@0: if ((n % 10) == 1 && !(isBetween((n % 100), 11, 19))) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: "11": function (n) { michael@0: if ((isBetween((n % 10), 2, 4)) && !(isBetween((n % 100), 12, 14))) michael@0: return "few"; michael@0: if ((n % 10) == 0 || (isBetween((n % 10), 5, 9)) || (isBetween((n % 100), 11, 14))) michael@0: return "many"; michael@0: if ((n % 10) == 1 && (n % 100) != 11) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: "12": function (n) { michael@0: if ((isBetween(n, 2, 4))) michael@0: return "few"; michael@0: if (n == 1) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: "13": function (n) { michael@0: if ((isBetween((n % 10), 2, 4)) && !(isBetween((n % 100), 12, 14))) michael@0: return "few"; michael@0: if (n != 1 && (isBetween((n % 10), 0, 1)) || (isBetween((n % 10), 5, 9)) || (isBetween((n % 100), 12, 14))) michael@0: return "many"; michael@0: if (n == 1) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: "14": function (n) { michael@0: if ((isBetween((n % 100), 3, 4))) michael@0: return "few"; michael@0: if ((n % 100) == 2) michael@0: return "two"; michael@0: if ((n % 100) == 1) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: "15": function (n) { michael@0: if (n == 0 || (isBetween((n % 100), 2, 10))) michael@0: return "few"; michael@0: if ((isBetween((n % 100), 11, 19))) michael@0: return "many"; michael@0: if (n == 1) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: "16": function (n) { michael@0: if ((n % 10) == 1 && n != 11) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: "17": function (n) { michael@0: if (n == 3) michael@0: return "few"; michael@0: if (n == 0) michael@0: return "zero"; michael@0: if (n == 6) michael@0: return "many"; michael@0: if (n == 2) michael@0: return "two"; michael@0: if (n == 1) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: "18": function (n) { michael@0: if (n == 0) michael@0: return "zero"; michael@0: if ((isBetween(n, 0, 2)) && n != 0 && n != 2) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: "19": function (n) { michael@0: if ((isBetween(n, 2, 10))) michael@0: return "few"; michael@0: if ((isBetween(n, 0, 1))) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: "20": function (n) { michael@0: if ((isBetween((n % 10), 3, 4) || ((n % 10) == 9)) && !(isBetween((n % 100), 10, 19) || isBetween((n % 100), 70, 79) || isBetween((n % 100), 90, 99))) michael@0: return "few"; michael@0: if ((n % 1000000) == 0 && n != 0) michael@0: return "many"; michael@0: if ((n % 10) == 2 && !isIn((n % 100), [12, 72, 92])) michael@0: return "two"; michael@0: if ((n % 10) == 1 && !isIn((n % 100), [11, 71, 91])) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: "21": function (n) { michael@0: if (n == 0) michael@0: return "zero"; michael@0: if (n == 1) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: "22": function (n) { michael@0: if ((isBetween(n, 0, 1)) || (isBetween(n, 11, 99))) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: "23": function (n) { michael@0: if ((isBetween((n % 10), 1, 2)) || (n % 20) == 0) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: "24": function (n) { michael@0: if ((isBetween(n, 3, 10) || isBetween(n, 13, 19))) michael@0: return "few"; michael@0: if (isIn(n, [2, 12])) michael@0: return "two"; michael@0: if (isIn(n, [1, 11])) michael@0: return "one"; michael@0: return "other" michael@0: }, michael@0: }; michael@0: michael@0: /** michael@0: * Return a function that gives the plural form name for a given integer michael@0: * for the specified `locale` michael@0: * let fun = getRulesForLocale('en'); michael@0: * fun(1) -> 'one' michael@0: * fun(0) -> 'other' michael@0: * fun(1000) -> 'other' michael@0: */ michael@0: exports.getRulesForLocale = function getRulesForLocale(locale) { michael@0: let index = LOCALES_TO_RULES[locale]; michael@0: if (!(index in RULES)) { michael@0: console.warn('Plural form unknown for locale "' + locale + '"'); michael@0: return function () { return "other"; }; michael@0: } michael@0: return RULES[index]; michael@0: } michael@0: