addon-sdk/source/lib/sdk/l10n/plural-rules.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:ba933440ed0e
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 // This file is automatically generated with /python-lib/plural-rules-generator.py
6 // Fetching data from: http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml
7
8 // Mapping of short locale name == to == > rule index in following list
9
10 module.metadata = {
11 "stability": "unstable"
12 };
13
14 const LOCALES_TO_RULES = {
15 "af": 3,
16 "ak": 4,
17 "am": 4,
18 "ar": 1,
19 "asa": 3,
20 "az": 0,
21 "be": 11,
22 "bem": 3,
23 "bez": 3,
24 "bg": 3,
25 "bh": 4,
26 "bm": 0,
27 "bn": 3,
28 "bo": 0,
29 "br": 20,
30 "brx": 3,
31 "bs": 11,
32 "ca": 3,
33 "cgg": 3,
34 "chr": 3,
35 "cs": 12,
36 "cy": 17,
37 "da": 3,
38 "de": 3,
39 "dv": 3,
40 "dz": 0,
41 "ee": 3,
42 "el": 3,
43 "en": 3,
44 "eo": 3,
45 "es": 3,
46 "et": 3,
47 "eu": 3,
48 "fa": 0,
49 "ff": 5,
50 "fi": 3,
51 "fil": 4,
52 "fo": 3,
53 "fr": 5,
54 "fur": 3,
55 "fy": 3,
56 "ga": 8,
57 "gd": 24,
58 "gl": 3,
59 "gsw": 3,
60 "gu": 3,
61 "guw": 4,
62 "gv": 23,
63 "ha": 3,
64 "haw": 3,
65 "he": 2,
66 "hi": 4,
67 "hr": 11,
68 "hu": 0,
69 "id": 0,
70 "ig": 0,
71 "ii": 0,
72 "is": 3,
73 "it": 3,
74 "iu": 7,
75 "ja": 0,
76 "jmc": 3,
77 "jv": 0,
78 "ka": 0,
79 "kab": 5,
80 "kaj": 3,
81 "kcg": 3,
82 "kde": 0,
83 "kea": 0,
84 "kk": 3,
85 "kl": 3,
86 "km": 0,
87 "kn": 0,
88 "ko": 0,
89 "ksb": 3,
90 "ksh": 21,
91 "ku": 3,
92 "kw": 7,
93 "lag": 18,
94 "lb": 3,
95 "lg": 3,
96 "ln": 4,
97 "lo": 0,
98 "lt": 10,
99 "lv": 6,
100 "mas": 3,
101 "mg": 4,
102 "mk": 16,
103 "ml": 3,
104 "mn": 3,
105 "mo": 9,
106 "mr": 3,
107 "ms": 0,
108 "mt": 15,
109 "my": 0,
110 "nah": 3,
111 "naq": 7,
112 "nb": 3,
113 "nd": 3,
114 "ne": 3,
115 "nl": 3,
116 "nn": 3,
117 "no": 3,
118 "nr": 3,
119 "nso": 4,
120 "ny": 3,
121 "nyn": 3,
122 "om": 3,
123 "or": 3,
124 "pa": 3,
125 "pap": 3,
126 "pl": 13,
127 "ps": 3,
128 "pt": 3,
129 "rm": 3,
130 "ro": 9,
131 "rof": 3,
132 "ru": 11,
133 "rwk": 3,
134 "sah": 0,
135 "saq": 3,
136 "se": 7,
137 "seh": 3,
138 "ses": 0,
139 "sg": 0,
140 "sh": 11,
141 "shi": 19,
142 "sk": 12,
143 "sl": 14,
144 "sma": 7,
145 "smi": 7,
146 "smj": 7,
147 "smn": 7,
148 "sms": 7,
149 "sn": 3,
150 "so": 3,
151 "sq": 3,
152 "sr": 11,
153 "ss": 3,
154 "ssy": 3,
155 "st": 3,
156 "sv": 3,
157 "sw": 3,
158 "syr": 3,
159 "ta": 3,
160 "te": 3,
161 "teo": 3,
162 "th": 0,
163 "ti": 4,
164 "tig": 3,
165 "tk": 3,
166 "tl": 4,
167 "tn": 3,
168 "to": 0,
169 "tr": 0,
170 "ts": 3,
171 "tzm": 22,
172 "uk": 11,
173 "ur": 3,
174 "ve": 3,
175 "vi": 0,
176 "vun": 3,
177 "wa": 4,
178 "wae": 3,
179 "wo": 0,
180 "xh": 3,
181 "xog": 3,
182 "yo": 0,
183 "zh": 0,
184 "zu": 3
185 };
186
187 // Utility functions for plural rules methods
188 function isIn(n, list) list.indexOf(n) !== -1;
189 function isBetween(n, start, end) start <= n && n <= end;
190
191 // List of all plural rules methods, that maps an integer to the plural form name to use
192 const RULES = {
193 "0": function (n) {
194
195 return "other"
196 },
197 "1": function (n) {
198 if ((isBetween((n % 100), 3, 10)))
199 return "few";
200 if (n == 0)
201 return "zero";
202 if ((isBetween((n % 100), 11, 99)))
203 return "many";
204 if (n == 2)
205 return "two";
206 if (n == 1)
207 return "one";
208 return "other"
209 },
210 "2": function (n) {
211 if (n != 0 && (n % 10) == 0)
212 return "many";
213 if (n == 2)
214 return "two";
215 if (n == 1)
216 return "one";
217 return "other"
218 },
219 "3": function (n) {
220 if (n == 1)
221 return "one";
222 return "other"
223 },
224 "4": function (n) {
225 if ((isBetween(n, 0, 1)))
226 return "one";
227 return "other"
228 },
229 "5": function (n) {
230 if ((isBetween(n, 0, 2)) && n != 2)
231 return "one";
232 return "other"
233 },
234 "6": function (n) {
235 if (n == 0)
236 return "zero";
237 if ((n % 10) == 1 && (n % 100) != 11)
238 return "one";
239 return "other"
240 },
241 "7": function (n) {
242 if (n == 2)
243 return "two";
244 if (n == 1)
245 return "one";
246 return "other"
247 },
248 "8": function (n) {
249 if ((isBetween(n, 3, 6)))
250 return "few";
251 if ((isBetween(n, 7, 10)))
252 return "many";
253 if (n == 2)
254 return "two";
255 if (n == 1)
256 return "one";
257 return "other"
258 },
259 "9": function (n) {
260 if (n == 0 || n != 1 && (isBetween((n % 100), 1, 19)))
261 return "few";
262 if (n == 1)
263 return "one";
264 return "other"
265 },
266 "10": function (n) {
267 if ((isBetween((n % 10), 2, 9)) && !(isBetween((n % 100), 11, 19)))
268 return "few";
269 if ((n % 10) == 1 && !(isBetween((n % 100), 11, 19)))
270 return "one";
271 return "other"
272 },
273 "11": function (n) {
274 if ((isBetween((n % 10), 2, 4)) && !(isBetween((n % 100), 12, 14)))
275 return "few";
276 if ((n % 10) == 0 || (isBetween((n % 10), 5, 9)) || (isBetween((n % 100), 11, 14)))
277 return "many";
278 if ((n % 10) == 1 && (n % 100) != 11)
279 return "one";
280 return "other"
281 },
282 "12": function (n) {
283 if ((isBetween(n, 2, 4)))
284 return "few";
285 if (n == 1)
286 return "one";
287 return "other"
288 },
289 "13": function (n) {
290 if ((isBetween((n % 10), 2, 4)) && !(isBetween((n % 100), 12, 14)))
291 return "few";
292 if (n != 1 && (isBetween((n % 10), 0, 1)) || (isBetween((n % 10), 5, 9)) || (isBetween((n % 100), 12, 14)))
293 return "many";
294 if (n == 1)
295 return "one";
296 return "other"
297 },
298 "14": function (n) {
299 if ((isBetween((n % 100), 3, 4)))
300 return "few";
301 if ((n % 100) == 2)
302 return "two";
303 if ((n % 100) == 1)
304 return "one";
305 return "other"
306 },
307 "15": function (n) {
308 if (n == 0 || (isBetween((n % 100), 2, 10)))
309 return "few";
310 if ((isBetween((n % 100), 11, 19)))
311 return "many";
312 if (n == 1)
313 return "one";
314 return "other"
315 },
316 "16": function (n) {
317 if ((n % 10) == 1 && n != 11)
318 return "one";
319 return "other"
320 },
321 "17": function (n) {
322 if (n == 3)
323 return "few";
324 if (n == 0)
325 return "zero";
326 if (n == 6)
327 return "many";
328 if (n == 2)
329 return "two";
330 if (n == 1)
331 return "one";
332 return "other"
333 },
334 "18": function (n) {
335 if (n == 0)
336 return "zero";
337 if ((isBetween(n, 0, 2)) && n != 0 && n != 2)
338 return "one";
339 return "other"
340 },
341 "19": function (n) {
342 if ((isBetween(n, 2, 10)))
343 return "few";
344 if ((isBetween(n, 0, 1)))
345 return "one";
346 return "other"
347 },
348 "20": function (n) {
349 if ((isBetween((n % 10), 3, 4) || ((n % 10) == 9)) && !(isBetween((n % 100), 10, 19) || isBetween((n % 100), 70, 79) || isBetween((n % 100), 90, 99)))
350 return "few";
351 if ((n % 1000000) == 0 && n != 0)
352 return "many";
353 if ((n % 10) == 2 && !isIn((n % 100), [12, 72, 92]))
354 return "two";
355 if ((n % 10) == 1 && !isIn((n % 100), [11, 71, 91]))
356 return "one";
357 return "other"
358 },
359 "21": function (n) {
360 if (n == 0)
361 return "zero";
362 if (n == 1)
363 return "one";
364 return "other"
365 },
366 "22": function (n) {
367 if ((isBetween(n, 0, 1)) || (isBetween(n, 11, 99)))
368 return "one";
369 return "other"
370 },
371 "23": function (n) {
372 if ((isBetween((n % 10), 1, 2)) || (n % 20) == 0)
373 return "one";
374 return "other"
375 },
376 "24": function (n) {
377 if ((isBetween(n, 3, 10) || isBetween(n, 13, 19)))
378 return "few";
379 if (isIn(n, [2, 12]))
380 return "two";
381 if (isIn(n, [1, 11]))
382 return "one";
383 return "other"
384 },
385 };
386
387 /**
388 * Return a function that gives the plural form name for a given integer
389 * for the specified `locale`
390 * let fun = getRulesForLocale('en');
391 * fun(1) -> 'one'
392 * fun(0) -> 'other'
393 * fun(1000) -> 'other'
394 */
395 exports.getRulesForLocale = function getRulesForLocale(locale) {
396 let index = LOCALES_TO_RULES[locale];
397 if (!(index in RULES)) {
398 console.warn('Plural form unknown for locale "' + locale + '"');
399 return function () { return "other"; };
400 }
401 return RULES[index];
402 }
403

mercurial