/* 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

module.metadata = {
  "stability": "unstable"
};

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

// Utility functions for plural rules methods
function isIn(n, list) {
  return list.indexOf(n) !== -1;
}
function isBetween(n, start, end) {
  return 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 != 0 && (n % 10) == 0)
      return "many";
    if (n == 2)
      return "two";
    if (n == 1)
      return "one";
    return "other"
  },
  "3": function (n) {
    if (n == 1)
      return "one";
    return "other"
  },
  "4": function (n) {
    if ((isBetween(n, 0, 1)))
      return "one";
    return "other"
  },
  "5": function (n) {
    if ((isBetween(n, 0, 2)) && n != 2)
      return "one";
    return "other"
  },
  "6": function (n) {
    if (n == 0)
      return "zero";
    if ((n % 10) == 1 && (n % 100) != 11)
      return "one";
    return "other"
  },
  "7": function (n) {
    if (n == 2)
      return "two";
    if (n == 1)
      return "one";
    return "other"
  },
  "8": 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"
  },
  "9": function (n) {
    if (n == 0 || n != 1 && (isBetween((n % 100), 1, 19)))
      return "few";
    if (n == 1)
      return "one";
    return "other"
  },
  "10": 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"
  },
  "11": 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"
  },
  "12": function (n) {
    if ((isBetween(n, 2, 4)))
      return "few";
    if (n == 1)
      return "one";
    return "other"
  },
  "13": 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"
  },
  "14": function (n) {
    if ((isBetween((n % 100), 3, 4)))
      return "few";
    if ((n % 100) == 2)
      return "two";
    if ((n % 100) == 1)
      return "one";
    return "other"
  },
  "15": 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"
  },
  "16": function (n) {
    if ((n % 10) == 1 && n != 11)
      return "one";
    return "other"
  },
  "17": 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"
  },
  "18": function (n) {
    if (n == 0)
      return "zero";
    if ((isBetween(n, 0, 2)) && n != 0 && n != 2)
      return "one";
    return "other"
  },
  "19": function (n) {
    if ((isBetween(n, 2, 10)))
      return "few";
    if ((isBetween(n, 0, 1)))
      return "one";
    return "other"
  },
  "20": 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"
  },
  "21": function (n) {
    if (n == 0)
      return "zero";
    if (n == 1)
      return "one";
    return "other"
  },
  "22": function (n) {
    if ((isBetween(n, 0, 1)) || (isBetween(n, 11, 99)))
      return "one";
    return "other"
  },
  "23": function (n) {
    if ((isBetween((n % 10), 1, 2)) || (n % 20) == 0)
      return "one";
    return "other"
  },
  "24": 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)) {
    console.warn('Plural form unknown for locale "' + locale + '"');
    return function () { return "other"; };
  }
  return RULES[index];
}