1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/addon-sdk/source/lib/sdk/l10n/plural-rules.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,403 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +// This file is automatically generated with /python-lib/plural-rules-generator.py 1.9 +// Fetching data from: http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml 1.10 + 1.11 +// Mapping of short locale name == to == > rule index in following list 1.12 + 1.13 +module.metadata = { 1.14 + "stability": "unstable" 1.15 +}; 1.16 + 1.17 +const LOCALES_TO_RULES = { 1.18 + "af": 3, 1.19 + "ak": 4, 1.20 + "am": 4, 1.21 + "ar": 1, 1.22 + "asa": 3, 1.23 + "az": 0, 1.24 + "be": 11, 1.25 + "bem": 3, 1.26 + "bez": 3, 1.27 + "bg": 3, 1.28 + "bh": 4, 1.29 + "bm": 0, 1.30 + "bn": 3, 1.31 + "bo": 0, 1.32 + "br": 20, 1.33 + "brx": 3, 1.34 + "bs": 11, 1.35 + "ca": 3, 1.36 + "cgg": 3, 1.37 + "chr": 3, 1.38 + "cs": 12, 1.39 + "cy": 17, 1.40 + "da": 3, 1.41 + "de": 3, 1.42 + "dv": 3, 1.43 + "dz": 0, 1.44 + "ee": 3, 1.45 + "el": 3, 1.46 + "en": 3, 1.47 + "eo": 3, 1.48 + "es": 3, 1.49 + "et": 3, 1.50 + "eu": 3, 1.51 + "fa": 0, 1.52 + "ff": 5, 1.53 + "fi": 3, 1.54 + "fil": 4, 1.55 + "fo": 3, 1.56 + "fr": 5, 1.57 + "fur": 3, 1.58 + "fy": 3, 1.59 + "ga": 8, 1.60 + "gd": 24, 1.61 + "gl": 3, 1.62 + "gsw": 3, 1.63 + "gu": 3, 1.64 + "guw": 4, 1.65 + "gv": 23, 1.66 + "ha": 3, 1.67 + "haw": 3, 1.68 + "he": 2, 1.69 + "hi": 4, 1.70 + "hr": 11, 1.71 + "hu": 0, 1.72 + "id": 0, 1.73 + "ig": 0, 1.74 + "ii": 0, 1.75 + "is": 3, 1.76 + "it": 3, 1.77 + "iu": 7, 1.78 + "ja": 0, 1.79 + "jmc": 3, 1.80 + "jv": 0, 1.81 + "ka": 0, 1.82 + "kab": 5, 1.83 + "kaj": 3, 1.84 + "kcg": 3, 1.85 + "kde": 0, 1.86 + "kea": 0, 1.87 + "kk": 3, 1.88 + "kl": 3, 1.89 + "km": 0, 1.90 + "kn": 0, 1.91 + "ko": 0, 1.92 + "ksb": 3, 1.93 + "ksh": 21, 1.94 + "ku": 3, 1.95 + "kw": 7, 1.96 + "lag": 18, 1.97 + "lb": 3, 1.98 + "lg": 3, 1.99 + "ln": 4, 1.100 + "lo": 0, 1.101 + "lt": 10, 1.102 + "lv": 6, 1.103 + "mas": 3, 1.104 + "mg": 4, 1.105 + "mk": 16, 1.106 + "ml": 3, 1.107 + "mn": 3, 1.108 + "mo": 9, 1.109 + "mr": 3, 1.110 + "ms": 0, 1.111 + "mt": 15, 1.112 + "my": 0, 1.113 + "nah": 3, 1.114 + "naq": 7, 1.115 + "nb": 3, 1.116 + "nd": 3, 1.117 + "ne": 3, 1.118 + "nl": 3, 1.119 + "nn": 3, 1.120 + "no": 3, 1.121 + "nr": 3, 1.122 + "nso": 4, 1.123 + "ny": 3, 1.124 + "nyn": 3, 1.125 + "om": 3, 1.126 + "or": 3, 1.127 + "pa": 3, 1.128 + "pap": 3, 1.129 + "pl": 13, 1.130 + "ps": 3, 1.131 + "pt": 3, 1.132 + "rm": 3, 1.133 + "ro": 9, 1.134 + "rof": 3, 1.135 + "ru": 11, 1.136 + "rwk": 3, 1.137 + "sah": 0, 1.138 + "saq": 3, 1.139 + "se": 7, 1.140 + "seh": 3, 1.141 + "ses": 0, 1.142 + "sg": 0, 1.143 + "sh": 11, 1.144 + "shi": 19, 1.145 + "sk": 12, 1.146 + "sl": 14, 1.147 + "sma": 7, 1.148 + "smi": 7, 1.149 + "smj": 7, 1.150 + "smn": 7, 1.151 + "sms": 7, 1.152 + "sn": 3, 1.153 + "so": 3, 1.154 + "sq": 3, 1.155 + "sr": 11, 1.156 + "ss": 3, 1.157 + "ssy": 3, 1.158 + "st": 3, 1.159 + "sv": 3, 1.160 + "sw": 3, 1.161 + "syr": 3, 1.162 + "ta": 3, 1.163 + "te": 3, 1.164 + "teo": 3, 1.165 + "th": 0, 1.166 + "ti": 4, 1.167 + "tig": 3, 1.168 + "tk": 3, 1.169 + "tl": 4, 1.170 + "tn": 3, 1.171 + "to": 0, 1.172 + "tr": 0, 1.173 + "ts": 3, 1.174 + "tzm": 22, 1.175 + "uk": 11, 1.176 + "ur": 3, 1.177 + "ve": 3, 1.178 + "vi": 0, 1.179 + "vun": 3, 1.180 + "wa": 4, 1.181 + "wae": 3, 1.182 + "wo": 0, 1.183 + "xh": 3, 1.184 + "xog": 3, 1.185 + "yo": 0, 1.186 + "zh": 0, 1.187 + "zu": 3 1.188 +}; 1.189 + 1.190 +// Utility functions for plural rules methods 1.191 +function isIn(n, list) list.indexOf(n) !== -1; 1.192 +function isBetween(n, start, end) start <= n && n <= end; 1.193 + 1.194 +// List of all plural rules methods, that maps an integer to the plural form name to use 1.195 +const RULES = { 1.196 + "0": function (n) { 1.197 + 1.198 + return "other" 1.199 + }, 1.200 + "1": function (n) { 1.201 + if ((isBetween((n % 100), 3, 10))) 1.202 + return "few"; 1.203 + if (n == 0) 1.204 + return "zero"; 1.205 + if ((isBetween((n % 100), 11, 99))) 1.206 + return "many"; 1.207 + if (n == 2) 1.208 + return "two"; 1.209 + if (n == 1) 1.210 + return "one"; 1.211 + return "other" 1.212 + }, 1.213 + "2": function (n) { 1.214 + if (n != 0 && (n % 10) == 0) 1.215 + return "many"; 1.216 + if (n == 2) 1.217 + return "two"; 1.218 + if (n == 1) 1.219 + return "one"; 1.220 + return "other" 1.221 + }, 1.222 + "3": function (n) { 1.223 + if (n == 1) 1.224 + return "one"; 1.225 + return "other" 1.226 + }, 1.227 + "4": function (n) { 1.228 + if ((isBetween(n, 0, 1))) 1.229 + return "one"; 1.230 + return "other" 1.231 + }, 1.232 + "5": function (n) { 1.233 + if ((isBetween(n, 0, 2)) && n != 2) 1.234 + return "one"; 1.235 + return "other" 1.236 + }, 1.237 + "6": function (n) { 1.238 + if (n == 0) 1.239 + return "zero"; 1.240 + if ((n % 10) == 1 && (n % 100) != 11) 1.241 + return "one"; 1.242 + return "other" 1.243 + }, 1.244 + "7": function (n) { 1.245 + if (n == 2) 1.246 + return "two"; 1.247 + if (n == 1) 1.248 + return "one"; 1.249 + return "other" 1.250 + }, 1.251 + "8": function (n) { 1.252 + if ((isBetween(n, 3, 6))) 1.253 + return "few"; 1.254 + if ((isBetween(n, 7, 10))) 1.255 + return "many"; 1.256 + if (n == 2) 1.257 + return "two"; 1.258 + if (n == 1) 1.259 + return "one"; 1.260 + return "other" 1.261 + }, 1.262 + "9": function (n) { 1.263 + if (n == 0 || n != 1 && (isBetween((n % 100), 1, 19))) 1.264 + return "few"; 1.265 + if (n == 1) 1.266 + return "one"; 1.267 + return "other" 1.268 + }, 1.269 + "10": function (n) { 1.270 + if ((isBetween((n % 10), 2, 9)) && !(isBetween((n % 100), 11, 19))) 1.271 + return "few"; 1.272 + if ((n % 10) == 1 && !(isBetween((n % 100), 11, 19))) 1.273 + return "one"; 1.274 + return "other" 1.275 + }, 1.276 + "11": function (n) { 1.277 + if ((isBetween((n % 10), 2, 4)) && !(isBetween((n % 100), 12, 14))) 1.278 + return "few"; 1.279 + if ((n % 10) == 0 || (isBetween((n % 10), 5, 9)) || (isBetween((n % 100), 11, 14))) 1.280 + return "many"; 1.281 + if ((n % 10) == 1 && (n % 100) != 11) 1.282 + return "one"; 1.283 + return "other" 1.284 + }, 1.285 + "12": function (n) { 1.286 + if ((isBetween(n, 2, 4))) 1.287 + return "few"; 1.288 + if (n == 1) 1.289 + return "one"; 1.290 + return "other" 1.291 + }, 1.292 + "13": function (n) { 1.293 + if ((isBetween((n % 10), 2, 4)) && !(isBetween((n % 100), 12, 14))) 1.294 + return "few"; 1.295 + if (n != 1 && (isBetween((n % 10), 0, 1)) || (isBetween((n % 10), 5, 9)) || (isBetween((n % 100), 12, 14))) 1.296 + return "many"; 1.297 + if (n == 1) 1.298 + return "one"; 1.299 + return "other" 1.300 + }, 1.301 + "14": function (n) { 1.302 + if ((isBetween((n % 100), 3, 4))) 1.303 + return "few"; 1.304 + if ((n % 100) == 2) 1.305 + return "two"; 1.306 + if ((n % 100) == 1) 1.307 + return "one"; 1.308 + return "other" 1.309 + }, 1.310 + "15": function (n) { 1.311 + if (n == 0 || (isBetween((n % 100), 2, 10))) 1.312 + return "few"; 1.313 + if ((isBetween((n % 100), 11, 19))) 1.314 + return "many"; 1.315 + if (n == 1) 1.316 + return "one"; 1.317 + return "other" 1.318 + }, 1.319 + "16": function (n) { 1.320 + if ((n % 10) == 1 && n != 11) 1.321 + return "one"; 1.322 + return "other" 1.323 + }, 1.324 + "17": function (n) { 1.325 + if (n == 3) 1.326 + return "few"; 1.327 + if (n == 0) 1.328 + return "zero"; 1.329 + if (n == 6) 1.330 + return "many"; 1.331 + if (n == 2) 1.332 + return "two"; 1.333 + if (n == 1) 1.334 + return "one"; 1.335 + return "other" 1.336 + }, 1.337 + "18": function (n) { 1.338 + if (n == 0) 1.339 + return "zero"; 1.340 + if ((isBetween(n, 0, 2)) && n != 0 && n != 2) 1.341 + return "one"; 1.342 + return "other" 1.343 + }, 1.344 + "19": function (n) { 1.345 + if ((isBetween(n, 2, 10))) 1.346 + return "few"; 1.347 + if ((isBetween(n, 0, 1))) 1.348 + return "one"; 1.349 + return "other" 1.350 + }, 1.351 + "20": function (n) { 1.352 + if ((isBetween((n % 10), 3, 4) || ((n % 10) == 9)) && !(isBetween((n % 100), 10, 19) || isBetween((n % 100), 70, 79) || isBetween((n % 100), 90, 99))) 1.353 + return "few"; 1.354 + if ((n % 1000000) == 0 && n != 0) 1.355 + return "many"; 1.356 + if ((n % 10) == 2 && !isIn((n % 100), [12, 72, 92])) 1.357 + return "two"; 1.358 + if ((n % 10) == 1 && !isIn((n % 100), [11, 71, 91])) 1.359 + return "one"; 1.360 + return "other" 1.361 + }, 1.362 + "21": function (n) { 1.363 + if (n == 0) 1.364 + return "zero"; 1.365 + if (n == 1) 1.366 + return "one"; 1.367 + return "other" 1.368 + }, 1.369 + "22": function (n) { 1.370 + if ((isBetween(n, 0, 1)) || (isBetween(n, 11, 99))) 1.371 + return "one"; 1.372 + return "other" 1.373 + }, 1.374 + "23": function (n) { 1.375 + if ((isBetween((n % 10), 1, 2)) || (n % 20) == 0) 1.376 + return "one"; 1.377 + return "other" 1.378 + }, 1.379 + "24": function (n) { 1.380 + if ((isBetween(n, 3, 10) || isBetween(n, 13, 19))) 1.381 + return "few"; 1.382 + if (isIn(n, [2, 12])) 1.383 + return "two"; 1.384 + if (isIn(n, [1, 11])) 1.385 + return "one"; 1.386 + return "other" 1.387 + }, 1.388 +}; 1.389 + 1.390 +/** 1.391 + * Return a function that gives the plural form name for a given integer 1.392 + * for the specified `locale` 1.393 + * let fun = getRulesForLocale('en'); 1.394 + * fun(1) -> 'one' 1.395 + * fun(0) -> 'other' 1.396 + * fun(1000) -> 'other' 1.397 + */ 1.398 +exports.getRulesForLocale = function getRulesForLocale(locale) { 1.399 + let index = LOCALES_TO_RULES[locale]; 1.400 + if (!(index in RULES)) { 1.401 + console.warn('Plural form unknown for locale "' + locale + '"'); 1.402 + return function () { return "other"; }; 1.403 + } 1.404 + return RULES[index]; 1.405 +} 1.406 +