1 /* global pluralRuleParser */
7 // CLDR plural rules generated using
8 // libs/CLDRPluralRuleParser/tools/PluralXML2JSON.html
20 few
: 'n % 100 = 3..10',
21 many
: 'n % 100 = 11..99'
27 few
: 'n % 100 = 3..10',
28 many
: 'n % 100 = 11..99'
34 one
: 'n % 10 = 1 and n % 100 != 11',
35 few
: 'n % 10 = 2..4 and n % 100 != 12..14',
36 many
: 'n % 10 = 0 or n % 10 = 5..9 or n % 100 = 11..14'
45 one
: 'n % 10 = 1 and n % 100 != 11,71,91',
46 two
: 'n % 10 = 2 and n % 100 != 12,72,92',
47 few
: 'n % 10 = 3..4,9 and n % 100 != 10..19,70..79,90..99',
48 many
: 'n != 0 and n % 1000000 = 0'
51 one
: 'v = 0 and i % 10 = 1 and i % 100 != 11 or f % 10 = 1 and f % 100 != 11',
52 few
: 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14'
55 one
: 'i = 1 and v = 0',
56 few
: 'i = 2..4 and v = 0',
67 one
: 'n = 1 or t != 0 and i = 0,1'
70 one
: 'v = 0 and i % 100 = 1 or f % 100 = 1',
71 two
: 'v = 0 and i % 100 = 2 or f % 100 = 2',
72 few
: 'v = 0 and i % 100 = 3..4 or f % 100 = 3..4'
81 one
: 'v = 0 and i = 1,2,3 or v = 0 and i % 10 != 4,6,9 or v != 0 and f % 10 != 4,6,9'
95 few
: 'n = 3..10,13..19'
104 one
: 'v = 0 and i % 10 = 1',
105 two
: 'v = 0 and i % 10 = 2',
106 few
: 'v = 0 and i % 100 = 0,20,40,60,80',
110 one
: 'i = 1 and v = 0',
111 two
: 'i = 2 and v = 0',
112 many
: 'v = 0 and n != 0..10 and n % 10 = 0'
115 one
: 'i = 0 or n = 1'
118 one
: 'v = 0 and i % 10 = 1 and i % 100 != 11 or f % 10 = 1 and f % 100 != 11',
119 few
: 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14'
122 one
: 'v = 0 and i % 100 = 1 or f % 100 = 1',
123 two
: 'v = 0 and i % 100 = 2 or f % 100 = 2',
124 few
: 'v = 0 and i % 100 = 3..4 or f % 100 = 3..4'
130 one
: 't = 0 and i % 10 = 1 and i % 100 != 11 or t != 0'
137 one
: 'i = 1 and v = 0',
138 two
: 'i = 2 and v = 0',
139 many
: 'v = 0 and n != 0..10 and n % 10 = 0'
145 one
: 'i = 0 or n = 1'
153 one
: 'i = 0,1 and n != 0'
159 one
: 'n % 10 = 1 and n % 100 != 11..19',
160 few
: 'n % 10 = 2..9 and n % 100 != 11..19',
164 zero
: 'n % 10 = 0 or n % 100 = 11..19 or v = 2 and f % 100 = 11..19',
165 one
: 'n % 10 = 1 and n % 100 != 11 or v = 2 and f % 10 = 1 and f % 100 != 11 or v != 2 and f % 10 = 1'
171 one
: 'v = 0 and i % 10 = 1 or f % 10 = 1'
174 one
: 'i = 1 and v = 0',
175 few
: 'v != 0 or n = 0 or n != 1 and n % 100 = 1..19'
178 one
: 'i = 0 or n = 1'
182 few
: 'n = 0 or n % 100 = 2..10',
183 many
: 'n % 100 = 11..19'
196 one
: 'i = 1 and v = 0',
197 few
: 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14',
198 many
: 'v = 0 and i != 1 and i % 10 = 0..1 or v = 0 and i % 10 = 5..9 or v = 0 and i % 100 = 12..14'
201 zero
: 'n % 10 = 0 or n % 100 = 11..19 or v = 2 and f % 100 = 11..19',
202 one
: 'n % 10 = 1 and n % 100 != 11 or v = 2 and f % 10 = 1 and f % 100 != 11 or v != 2 and f % 10 = 1'
208 one
: 'i = 1 and v = 0',
209 few
: 'v != 0 or n = 0 or n != 1 and n % 100 = 1..19'
212 one
: 'v = 0 and i % 10 = 1 and i % 100 != 11',
213 few
: 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14',
214 many
: 'v = 0 and i % 10 = 0 or v = 0 and i % 10 = 5..9 or v = 0 and i % 100 = 11..14'
221 one
: 'v = 0 and i % 10 = 1 and i % 100 != 11 or f % 10 = 1 and f % 100 != 11',
222 few
: 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14'
225 one
: 'i = 0 or n = 1',
229 one
: 'n = 0,1 or i = 0 and f = 1'
232 one
: 'i = 1 and v = 0',
233 few
: 'i = 2..4 and v = 0',
237 one
: 'v = 0 and i % 100 = 1',
238 two
: 'v = 0 and i % 100 = 2',
239 few
: 'v = 0 and i % 100 = 3..4 or v != 0'
262 one
: 'v = 0 and i % 10 = 1 and i % 100 != 11 or f % 10 = 1 and f % 100 != 11',
263 few
: 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14'
269 one
: 'v = 0 and i = 1,2,3 or v = 0 and i % 10 != 4,6,9 or v != 0 and f % 10 != 4,6,9'
272 one
: 'n = 0..1 or n = 11..99'
275 one
: 'v = 0 and i % 10 = 1 and i % 100 != 11',
276 few
: 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14',
277 many
: 'v = 0 and i % 10 = 0 or v = 0 and i % 10 = 5..9 or v = 0 and i % 100 = 11..14'
283 one
: 'i = 0 or n = 1'
289 * Plural form transformations, needed for some languages.
291 * @param {integer} count
292 * Non-localized quantifier
293 * @param {Array} forms
294 * List of plural forms
295 * @return {string} Correct form for quantifier in this language
297 convertPlural: function ( count
, forms
) {
301 explicitPluralPattern
= new RegExp( '\\d+=', 'i' ),
305 if ( !forms
|| forms
.length
=== 0 ) {
309 // Handle for Explicit 0= & 1= values
310 for ( index
= 0; index
< forms
.length
; index
++ ) {
311 form
= forms
[ index
];
312 if ( explicitPluralPattern
.test( form
) ) {
313 formCount
= parseInt( form
.slice( 0, form
.indexOf( '=' ) ), 10 );
314 if ( formCount
=== count
) {
315 return ( form
.slice( form
.indexOf( '=' ) + 1 ) );
317 forms
[ index
] = undefined;
321 forms
= $.map( forms
, function ( form
) {
322 if ( form
!== undefined ) {
327 pluralRules
= this.pluralRules
[ $.i18n().locale
];
329 if ( !pluralRules
) {
331 return ( count
=== 1 ) ? forms
[ 0 ] : forms
[ 1 ];
334 pluralFormIndex
= this.getPluralForm( count
, pluralRules
);
335 pluralFormIndex
= Math
.min( pluralFormIndex
, forms
.length
- 1 );
337 return forms
[ pluralFormIndex
];
341 * For the number, get the plural for index
343 * @param {integer} number
344 * @param {Object} pluralRules
345 * @return {integer} plural form index
347 getPluralForm: function ( number
, pluralRules
) {
349 pluralForms
= [ 'zero', 'one', 'two', 'few', 'many', 'other' ],
352 for ( i
= 0; i
< pluralForms
.length
; i
++ ) {
353 if ( pluralRules
[ pluralForms
[ i
] ] ) {
354 if ( pluralRuleParser( pluralRules
[ pluralForms
[ i
] ], number
) ) {
355 return pluralFormIndex
;
362 return pluralFormIndex
;
366 * Converts a number using digitTransformTable.
368 * @param {number} num Value to be converted
369 * @param {boolean} integer Convert the return value to an integer
370 * @return {string} The number converted into a String.
372 convertNumber: function ( num
, integer
) {
374 transformTable
, numberString
, convertedNumber
;
376 // Set the target Transform table:
377 transformTable
= this.digitTransformTable( $.i18n().locale
);
378 numberString
= String( num
);
379 convertedNumber
= '';
381 if ( !transformTable
) {
385 // Check if the restore to Latin number flag is set:
387 if ( parseFloat( num
, 10 ) === num
) {
393 for ( item
in transformTable
) {
394 tmp
[ transformTable
[ item
] ] = item
;
397 transformTable
= tmp
;
400 for ( i
= 0; i
< numberString
.length
; i
++ ) {
401 if ( transformTable
[ numberString
[ i
] ] ) {
402 convertedNumber
+= transformTable
[ numberString
[ i
] ];
404 convertedNumber
+= numberString
[ i
];
408 return integer
? parseFloat( convertedNumber
, 10 ) : convertedNumber
;
412 * Grammatical transformations, needed for inflected languages.
413 * Invoked by putting {{grammar:form|word}} in a message.
414 * Override this method for languages that need special grammar rules
415 * applied dynamically.
417 * @param {string} word
418 * @param {string} form
421 // eslint-disable-next-line no-unused-vars
422 convertGrammar: function ( word
, form
) {
427 * Provides an alternative text depending on specified gender. Usage
428 * {{gender:[gender|user object]|masculine|feminine|neutral}}. If second
429 * or third parameter are not specified, masculine is used.
431 * These details may be overriden per language.
433 * @param {string} gender
434 * male, female, or anything else for neutral.
435 * @param {Array} forms
436 * List of gender forms
440 gender: function ( gender
, forms
) {
441 if ( !forms
|| forms
.length
=== 0 ) {
445 while ( forms
.length
< 2 ) {
446 forms
.push( forms
[ forms
.length
- 1 ] );
449 if ( gender
=== 'male' ) {
453 if ( gender
=== 'female' ) {
457 return ( forms
.length
=== 3 ) ? forms
[ 2 ] : forms
[ 0 ];
461 * Get the digit transform table for the given language
462 * See http://cldr.unicode.org/translation/numbering-systems
464 * @param {string} language
465 * @return {Array|boolean} List of digits in the passed language or false
466 * representation, or boolean false if there is no information.
468 digitTransformTable: function ( language
) {
483 th
: '๐๑๒๓๔๕๖๗๘๙', // FIXME use iso 639 codes
484 bo
: '༠༡༢༣༤༥༦༧༨༩' // FIXME use iso 639 codes
487 if ( !tables
[ language
] ) {
491 return tables
[ language
].split( '' );
495 $.extend( $.i18n
.languages
, {