1 /*global pluralRuleParser */
6 // CLDR plural rules generated using
7 // libs/CLDRPluralRuleParser/tools/PluralXML2JSON.html
19 few: 'n % 100 = 3..10',
20 many: 'n % 100 = 11..99'
23 one: 'n % 10 = 1 and n % 100 != 11',
24 few: 'n % 10 = 2..4 and n % 100 != 12..14',
25 many: 'n % 10 = 0 or n % 10 = 5..9 or n % 100 = 11..14'
34 one: 'n % 10 = 1 and n % 100 != 11,71,91',
35 two: 'n % 10 = 2 and n % 100 != 12,72,92',
36 few: 'n % 10 = 3..4,9 and n % 100 != 10..19,70..79,90..99',
37 many: 'n != 0 and n % 1000000 = 0'
40 one: 'v = 0 and i % 10 = 1 and i % 100 != 11 or f % 10 = 1 and f % 100 != 11',
41 few: 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14'
44 one: 'i = 1 and v = 0',
45 few: 'i = 2..4 and v = 0',
56 one: 'n = 1 or t != 0 and i = 0,1'
65 one: 'i = 0..1 and v = 0'
79 few: 'n = 3..10,13..19'
90 few: 'n % 100 = 0,20,40,60'
93 one: 'i = 1 and v = 0',
94 two: 'i = 2 and v = 0',
95 many: 'v = 0 and n != 0..10 and n % 10 = 0'
101 one: 'v = 0 and i % 10 = 1 and i % 100 != 11 or f % 10 = 1 and f % 100 != 11',
102 few: 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14'
108 one: 't = 0 and i % 10 = 1 and i % 100 != 11 or t != 0'
115 one: 'i = 1 and v = 0',
116 two: 'i = 2 and v = 0',
117 many: 'v = 0 and n != 0..10 and n % 10 = 0'
123 one: 'i = 0 or n = 1'
131 one: 'i = 0,1 and n != 0'
137 one: 'n % 10 = 1 and n % 100 != 11..19',
138 few: 'n % 10 = 2..9 and n % 100 != 11..19',
142 zero: 'n % 10 = 0 or n % 100 = 11..19 or v = 2 and f % 100 = 11..19',
143 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'
149 one: 'v = 0 and i % 10 = 1 or f % 10 = 1'
152 one: 'i = 1 and v = 0',
153 few: 'v != 0 or n = 0 or n != 1 and n % 100 = 1..19'
156 one: 'i = 0 or n = 1'
160 few: 'n = 0 or n % 100 = 2..10',
161 many: 'n % 100 = 11..19'
174 one: 'i = 1 and v = 0',
175 few: 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14',
176 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'
179 one: 'i = 1 and v = 0 or i = 0 and t = 1'
181 // jscs:disable requireCamelCaseOrUpperCaseIdentifiers
183 one: 'n = 1 and v = 0'
185 // jscs:enable requireCamelCaseOrUpperCaseIdentifiers
187 one: 'i = 1 and v = 0',
188 few: 'v != 0 or n = 0 or n != 1 and n % 100 = 1..19'
191 one: 'v = 0 and i % 10 = 1 and i % 100 != 11',
192 many: 'v = 0 and i % 10 = 0 or v = 0 and i % 10 = 5..9 or v = 0 and i % 100 = 11..14'
199 one: 'v = 0 and i % 10 = 1 and i % 100 != 11 or f % 10 = 1 and f % 100 != 11',
200 few: 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14'
203 one: 'i = 0 or n = 1',
207 one: 'n = 0,1 or i = 0 and f = 1'
210 one: 'i = 1 and v = 0',
211 few: 'i = 2..4 and v = 0',
215 one: 'v = 0 and i % 100 = 1',
216 two: 'v = 0 and i % 100 = 2',
217 few: 'v = 0 and i % 100 = 3..4 or v != 0'
240 one: 'v = 0 and i % 10 = 1 and i % 100 != 11 or f % 10 = 1 and f % 100 != 11',
241 few: 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14'
247 one: 'i = 0..1 and v = 0'
250 one: 'n = 0..1 or n = 11..99'
253 one: 'v = 0 and i % 10 = 1 and i % 100 != 11',
254 few: 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14',
255 many: 'v = 0 and i % 10 = 0 or v = 0 and i % 10 = 5..9 or v = 0 and i % 100 = 11..14'
261 one: 'i = 0 or n = 1'
266 * Plural form transformations, needed for some languages.
269 * integer Non-localized quantifier
271 * array List of plural forms
272 * @return string Correct form for quantifier in this language
274 convertPlural: function ( count, forms ) {
278 explicitPluralPattern = new RegExp( '\\d+=', 'i' ),
282 if ( !forms || forms.length === 0 ) {
286 // Handle for Explicit 0= & 1= values
287 for ( index = 0; index < forms.length; index++ ) {
289 if ( explicitPluralPattern.test( form ) ) {
290 formCount = parseInt( form.substring( 0, form.indexOf( '=' ) ), 10 );
291 if ( formCount === count ) {
292 return ( form.substr( form.indexOf( '=' ) + 1 ) );
294 forms[index] = undefined;
298 forms = $.map( forms, function ( form ) {
299 if ( form !== undefined ) {
304 pluralRules = this.pluralRules[$.i18n().locale];
306 if ( !pluralRules ) {
308 return ( count === 1 ) ? forms[0] : forms[1];
311 pluralFormIndex = this.getPluralForm( count, pluralRules );
312 pluralFormIndex = Math.min( pluralFormIndex, forms.length - 1 );
314 return forms[pluralFormIndex];
318 * For the number, get the plural for index
322 * @return plural form index
324 getPluralForm: function ( number, pluralRules ) {
326 pluralForms = [ 'zero', 'one', 'two', 'few', 'many', 'other' ],
329 for ( i = 0; i < pluralForms.length; i++ ) {
330 if ( pluralRules[pluralForms[i]] ) {
331 if ( pluralRuleParser( pluralRules[pluralForms[i]], number ) ) {
332 return pluralFormIndex;
339 return pluralFormIndex;
343 * Converts a number using digitTransformTable.
345 * @param {number} num Value to be converted
346 * @param {boolean} integer Convert the return value to an integer
348 convertNumber: function ( num, integer ) {
350 transformTable, numberString, convertedNumber;
352 // Set the target Transform table:
353 transformTable = this.digitTransformTable( $.i18n().locale );
354 numberString = String( num );
355 convertedNumber = '';
357 if ( !transformTable ) {
361 // Check if the restore to Latin number flag is set:
363 if ( parseFloat( num, 10 ) === num ) {
369 for ( item in transformTable ) {
370 tmp[transformTable[item]] = item;
373 transformTable = tmp;
376 for ( i = 0; i < numberString.length; i++ ) {
377 if ( transformTable[numberString[i]] ) {
378 convertedNumber += transformTable[numberString[i]];
380 convertedNumber += numberString[i];
384 return integer ? parseFloat( convertedNumber, 10 ) : convertedNumber;
388 * Grammatical transformations, needed for inflected languages.
389 * Invoked by putting {{grammar:form|word}} in a message.
390 * Override this method for languages that need special grammar rules
391 * applied dynamically.
393 * @param word {String}
394 * @param form {String}
397 convertGrammar: function ( word, form ) { /*jshint unused: false */
402 * Provides an alternative text depending on specified gender. Usage
403 * {{gender:[gender|user object]|masculine|feminine|neutral}}. If second
404 * or third parameter are not specified, masculine is used.
406 * These details may be overriden per language.
409 * string male, female, or anything else for neutral.
411 * array List of gender forms
415 gender: function ( gender, forms ) {
416 if ( !forms || forms.length === 0 ) {
420 while ( forms.length < 2 ) {
421 forms.push( forms[forms.length - 1] );
424 if ( gender === 'male' ) {
428 if ( gender === 'female' ) {
432 return ( forms.length === 3 ) ? forms[2] : forms[0];
436 * Get the digit transform table for the given language
437 * See http://cldr.unicode.org/translation/numbering-systems
439 * @returns {Array|boolean} List of digits in the passed language or false
440 * representation, or boolean false if there is no information.
442 digitTransformTable: function ( language ) {
457 th: '๐๑๒๓๔๕๖๗๘๙', // FIXME use iso 639 codes
458 bo: '༠༡༢༣༤༥༦༧༨༩' // FIXME use iso 639 codes
461 if ( !tables[language] ) {
465 return tables[language].split( '' );
469 $.extend( $.i18n.languages, {