/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// This file is automatically generated with /python-lib/plural-rules-generator.py
// Fetching data from: http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml

// Mapping of short locale name == to == > rule index in following list
const LOCALES_TO_RULES = {
  "af": 2, 
  "ak": 3, 
  "am": 3, 
  "ar": 1, 
  "asa": 2, 
  "az": 0, 
  "be": 10, 
  "bem": 2, 
  "bez": 2, 
  "bg": 2, 
  "bh": 3, 
  "bm": 0, 
  "bn": 2, 
  "bo": 0, 
  "br": 19, 
  "brx": 2, 
  "bs": 10, 
  "ca": 2, 
  "cgg": 2, 
  "chr": 2, 
  "cs": 11, 
  "cy": 16, 
  "da": 2, 
  "de": 2, 
  "dv": 2, 
  "dz": 0, 
  "ee": 2, 
  "el": 2, 
  "en": 2, 
  "eo": 2, 
  "es": 2, 
  "et": 2, 
  "eu": 2, 
  "fa": 0, 
  "ff": 4, 
  "fi": 2, 
  "fil": 3, 
  "fo": 2, 
  "fr": 4, 
  "fur": 2, 
  "fy": 2, 
  "ga": 7, 
  "gd": 23, 
  "gl": 2, 
  "gsw": 2, 
  "gu": 2, 
  "guw": 3, 
  "gv": 22, 
  "ha": 2, 
  "haw": 2, 
  "he": 2, 
  "hi": 3, 
  "hr": 10, 
  "hu": 0, 
  "id": 0, 
  "ig": 0, 
  "ii": 0, 
  "is": 2, 
  "it": 2, 
  "iu": 6, 
  "ja": 0, 
  "jmc": 2, 
  "jv": 0, 
  "ka": 0, 
  "kab": 4, 
  "kaj": 2, 
  "kcg": 2, 
  "kde": 0, 
  "kea": 0, 
  "kk": 2, 
  "kl": 2, 
  "km": 0, 
  "kn": 0, 
  "ko": 0, 
  "ksb": 2, 
  "ksh": 20, 
  "ku": 2, 
  "kw": 6, 
  "lag": 17, 
  "lb": 2, 
  "lg": 2, 
  "ln": 3, 
  "lo": 0, 
  "lt": 9, 
  "lv": 5, 
  "mas": 2, 
  "mg": 3, 
  "mk": 15, 
  "ml": 2, 
  "mn": 2, 
  "mo": 8, 
  "mr": 2, 
  "ms": 0, 
  "mt": 14, 
  "my": 0, 
  "nah": 2, 
  "naq": 6, 
  "nb": 2, 
  "nd": 2, 
  "ne": 2, 
  "nl": 2, 
  "nn": 2, 
  "no": 2, 
  "nr": 2, 
  "nso": 3, 
  "ny": 2, 
  "nyn": 2, 
  "om": 2, 
  "or": 2, 
  "pa": 2, 
  "pap": 2, 
  "pl": 12, 
  "ps": 2, 
  "pt": 2, 
  "rm": 2, 
  "ro": 8, 
  "rof": 2, 
  "ru": 10, 
  "rwk": 2, 
  "sah": 0, 
  "saq": 2, 
  "se": 6, 
  "seh": 2, 
  "ses": 0, 
  "sg": 0, 
  "sh": 10, 
  "shi": 18, 
  "sk": 11, 
  "sl": 13, 
  "sma": 6, 
  "smi": 6, 
  "smj": 6, 
  "smn": 6, 
  "sms": 6, 
  "sn": 2, 
  "so": 2, 
  "sq": 2, 
  "sr": 10, 
  "ss": 2, 
  "ssy": 2, 
  "st": 2, 
  "sv": 2, 
  "sw": 2, 
  "syr": 2, 
  "ta": 2, 
  "te": 2, 
  "teo": 2, 
  "th": 0, 
  "ti": 3, 
  "tig": 2, 
  "tk": 2, 
  "tl": 3, 
  "tn": 2, 
  "to": 0, 
  "tr": 0, 
  "ts": 2, 
  "tzm": 21, 
  "uk": 10, 
  "ur": 2, 
  "ve": 2, 
  "vi": 0, 
  "vun": 2, 
  "wa": 3, 
  "wae": 2, 
  "wo": 0, 
  "xh": 2, 
  "xog": 2, 
  "yo": 0, 
  "zh": 0, 
  "zu": 2
};

// Utility functions for plural rules methods
function isIn(n, list) list.indexOf(n) !== -1;
function isBetween(n, start, end) start <= n && n <= end;

// List of all plural rules methods, that maps an integer to the plural form name to use
const RULES = {
  "0": function (n) {
    
    return "other"
  },
  "1": function (n) {
    if ((isBetween((n % 100), 3, 10)))
      return "few";
    if (n == 0)
      return "zero";
    if ((isBetween((n % 100), 11, 99)))
      return "many";
    if (n == 2)
      return "two";
    if (n == 1)
      return "one";
    return "other"
  },
  "2": function (n) {
    if (n == 1)
      return "one";
    return "other"
  },
  "3": function (n) {
    if ((isBetween(n, 0, 1)))
      return "one";
    return "other"
  },
  "4": function (n) {
    if ((isBetween(n, 0, 2)) && n != 2)
      return "one";
    return "other"
  },
  "5": function (n) {
    if (n == 0)
      return "zero";
    if ((n % 10) == 1 && (n % 100) != 11)
      return "one";
    return "other"
  },
  "6": function (n) {
    if (n == 2)
      return "two";
    if (n == 1)
      return "one";
    return "other"
  },
  "7": function (n) {
    if ((isBetween(n, 3, 6)))
      return "few";
    if ((isBetween(n, 7, 10)))
      return "many";
    if (n == 2)
      return "two";
    if (n == 1)
      return "one";
    return "other"
  },
  "8": function (n) {
    if (n == 0 || n != 1 && (isBetween((n % 100), 1, 19)))
      return "few";
    if (n == 1)
      return "one";
    return "other"
  },
  "9": function (n) {
    if ((isBetween((n % 10), 2, 9)) && !(isBetween((n % 100), 11, 19)))
      return "few";
    if ((n % 10) == 1 && !(isBetween((n % 100), 11, 19)))
      return "one";
    return "other"
  },
  "10": function (n) {
    if ((isBetween((n % 10), 2, 4)) && !(isBetween((n % 100), 12, 14)))
      return "few";
    if ((n % 10) == 0 || (isBetween((n % 10), 5, 9)) || (isBetween((n % 100), 11, 14)))
      return "many";
    if ((n % 10) == 1 && (n % 100) != 11)
      return "one";
    return "other"
  },
  "11": function (n) {
    if ((isBetween(n, 2, 4)))
      return "few";
    if (n == 1)
      return "one";
    return "other"
  },
  "12": function (n) {
    if ((isBetween((n % 10), 2, 4)) && !(isBetween((n % 100), 12, 14)))
      return "few";
    if (n != 1 && (isBetween((n % 10), 0, 1)) || (isBetween((n % 10), 5, 9)) || (isBetween((n % 100), 12, 14)))
      return "many";
    if (n == 1)
      return "one";
    return "other"
  },
  "13": function (n) {
    if ((isBetween((n % 100), 3, 4)))
      return "few";
    if ((n % 100) == 2)
      return "two";
    if ((n % 100) == 1)
      return "one";
    return "other"
  },
  "14": function (n) {
    if (n == 0 || (isBetween((n % 100), 2, 10)))
      return "few";
    if ((isBetween((n % 100), 11, 19)))
      return "many";
    if (n == 1)
      return "one";
    return "other"
  },
  "15": function (n) {
    if ((n % 10) == 1 && n != 11)
      return "one";
    return "other"
  },
  "16": function (n) {
    if (n == 3)
      return "few";
    if (n == 0)
      return "zero";
    if (n == 6)
      return "many";
    if (n == 2)
      return "two";
    if (n == 1)
      return "one";
    return "other"
  },
  "17": function (n) {
    if (n == 0)
      return "zero";
    if ((isBetween(n, 0, 2)) && n != 0 && n != 2)
      return "one";
    return "other"
  },
  "18": function (n) {
    if ((isBetween(n, 2, 10)))
      return "few";
    if ((isBetween(n, 0, 1)))
      return "one";
    return "other"
  },
  "19": function (n) {
    if ((isBetween((n % 10), 3, 4) || ((n % 10) == 9)) && !(isBetween((n % 100), 10, 19) || isBetween((n % 100), 70, 79) || isBetween((n % 100), 90, 99)))
      return "few";
    if ((n % 1000000) == 0 && n != 0)
      return "many";
    if ((n % 10) == 2 && !isIn((n % 100), [12, 72, 92]))
      return "two";
    if ((n % 10) == 1 && !isIn((n % 100), [11, 71, 91]))
      return "one";
    return "other"
  },
  "20": function (n) {
    if (n == 0)
      return "zero";
    if (n == 1)
      return "one";
    return "other"
  },
  "21": function (n) {
    if ((isBetween(n, 0, 1)) || (isBetween(n, 11, 99)))
      return "one";
    return "other"
  },
  "22": function (n) {
    if ((isBetween((n % 10), 1, 2)) || (n % 20) == 0)
      return "one";
    return "other"
  },
  "23": function (n) {
    if ((isBetween(n, 3, 10) || isBetween(n, 13, 19)))
      return "few";
    if (isIn(n, [2, 12]))
      return "two";
    if (isIn(n, [1, 11]))
      return "one";
    return "other"
  },
};

/**
  * Return a function that gives the plural form name for a given integer
  * for the specified `locale`
  *   let fun = getRulesForLocale('en');
  *   fun(1)    -> 'one'
  *   fun(0)    -> 'other'
  *   fun(1000) -> 'other'
  */
exports.getRulesForLocale = function getRulesForLocale(locale) {
  let index = LOCALES_TO_RULES[locale];
  if (!(index in RULES))
    throw new Error('Plural form unknown for locale "' + locale + '"');
  return RULES[index];
}

