Merge "Update jquery.i18n to 8267e1dbef"

This commit is contained in:
Niklas Laxström
2016-05-03 08:31:40 +00:00
committed by Gerrit Code Review
20 changed files with 75 additions and 75 deletions

View File

@@ -51,7 +51,7 @@
if ( !m ) { if ( !m ) {
return null; return null;
} }
if ( m[2] === undefined ) { if ( m[ 2 ] === undefined ) {
return 'ltr'; return 'ltr';
} }
return 'rtl'; return 'rtl';
@@ -72,17 +72,17 @@
* direction inference). The latter is cleaner but still not widely supported. * direction inference). The latter is cleaner but still not widely supported.
*/ */
bidi: function ( nodes ) { bidi: function ( nodes ) {
var dir = strongDirFromContent( nodes[0] ); var dir = strongDirFromContent( nodes[ 0 ] );
if ( dir === 'ltr' ) { if ( dir === 'ltr' ) {
// Wrap in LEFT-TO-RIGHT EMBEDDING ... POP DIRECTIONAL FORMATTING // Wrap in LEFT-TO-RIGHT EMBEDDING ... POP DIRECTIONAL FORMATTING
return '\u202A' + nodes[0] + '\u202C'; return '\u202A' + nodes[ 0 ] + '\u202C';
} }
if ( dir === 'rtl' ) { if ( dir === 'rtl' ) {
// Wrap in RIGHT-TO-LEFT EMBEDDING ... POP DIRECTIONAL FORMATTING // Wrap in RIGHT-TO-LEFT EMBEDDING ... POP DIRECTIONAL FORMATTING
return '\u202B' + nodes[0] + '\u202C'; return '\u202B' + nodes[ 0 ] + '\u202C';
} }
// No strong directionality: do not wrap // No strong directionality: do not wrap
return nodes[0]; return nodes[ 0 ];
} }
} ); } );
}( jQuery ) ); }( jQuery ) );

View File

@@ -17,7 +17,7 @@
'use strict'; 'use strict';
var MessageParserEmitter = function () { var MessageParserEmitter = function () {
this.language = $.i18n.languages[String.locale] || $.i18n.languages['default']; this.language = $.i18n.languages[ String.locale ] || $.i18n.languages[ 'default' ];
}; };
MessageParserEmitter.prototype = { MessageParserEmitter.prototype = {
@@ -48,10 +48,10 @@
return messageParserEmitter.emit( n, replacements ); return messageParserEmitter.emit( n, replacements );
} ); } );
operation = node[0].toLowerCase(); operation = node[ 0 ].toLowerCase();
if ( typeof messageParserEmitter[operation] === 'function' ) { if ( typeof messageParserEmitter[ operation ] === 'function' ) {
ret = messageParserEmitter[operation]( subnodes, replacements ); ret = messageParserEmitter[ operation ]( subnodes, replacements );
} else { } else {
throw new Error( 'unknown operation "' + operation + '"' ); throw new Error( 'unknown operation "' + operation + '"' );
} }
@@ -106,11 +106,11 @@
* @return {string} replacement * @return {string} replacement
*/ */
replace: function ( nodes, replacements ) { replace: function ( nodes, replacements ) {
var index = parseInt( nodes[0], 10 ); var index = parseInt( nodes[ 0 ], 10 );
if ( index < replacements.length ) { if ( index < replacements.length ) {
// replacement is not a string, don't touch! // replacement is not a string, don't touch!
return replacements[index]; return replacements[ index ];
} else { } else {
// index not found, fallback to displaying variable // index not found, fallback to displaying variable
return '$' + ( index + 1 ); return '$' + ( index + 1 );
@@ -128,7 +128,7 @@
* language. * language.
*/ */
plural: function ( nodes ) { plural: function ( nodes ) {
var count = parseFloat( this.language.convertNumber( nodes[0], 10 ) ), var count = parseFloat( this.language.convertNumber( nodes[ 0 ], 10 ) ),
forms = nodes.slice( 1 ); forms = nodes.slice( 1 );
return forms.length ? this.language.convertPlural( count, forms ) : ''; return forms.length ? this.language.convertPlural( count, forms ) : '';
@@ -142,7 +142,7 @@
* @return {String} selected gender form according to current language * @return {String} selected gender form according to current language
*/ */
gender: function ( nodes ) { gender: function ( nodes ) {
var gender = nodes[0], var gender = nodes[ 0 ],
forms = nodes.slice( 1 ); forms = nodes.slice( 1 );
return this.language.gender( gender, forms ); return this.language.gender( gender, forms );
@@ -157,8 +157,8 @@
* language. * language.
*/ */
grammar: function ( nodes ) { grammar: function ( nodes ) {
var form = nodes[0], var form = nodes[ 0 ],
word = nodes[1]; word = nodes[ 1 ];
return word && form && this.language.convertGrammar( word, form ); return word && form && this.language.convertGrammar( word, form );
} }

View File

@@ -75,7 +75,7 @@
break; break;
} }
locale = ( $.i18n.fallbacks[i18n.locale] && $.i18n.fallbacks[i18n.locale][fallbackIndex] ) || locale = ( $.i18n.fallbacks[ i18n.locale ] && $.i18n.fallbacks[ i18n.locale ][ fallbackIndex ] ) ||
i18n.options.fallbackLocale; i18n.options.fallbackLocale;
$.i18n.log( 'Trying fallback locale for ' + i18n.locale + ': ' + locale ); $.i18n.log( 'Trying fallback locale for ' + i18n.locale + ': ' + locale );
@@ -146,12 +146,12 @@
source.split( '.' ).pop() !== 'json' source.split( '.' ).pop() !== 'json'
) { ) {
// Load specified locale then check for fallbacks when directory is specified in load() // Load specified locale then check for fallbacks when directory is specified in load()
sourceMap[locale] = source + '/' + locale + '.json'; sourceMap[ locale ] = source + '/' + locale + '.json';
fallbackLocales = ( $.i18n.fallbacks[locale] || [] ) fallbackLocales = ( $.i18n.fallbacks[ locale ] || [] )
.concat( this.options.fallbackLocale ); .concat( this.options.fallbackLocale );
for ( locIndex in fallbackLocales ) { for ( locIndex in fallbackLocales ) {
fallbackLocale = fallbackLocales[locIndex]; fallbackLocale = fallbackLocales[ locIndex ];
sourceMap[fallbackLocale] = source + '/' + fallbackLocale + '.json'; sourceMap[ fallbackLocale ] = source + '/' + fallbackLocale + '.json';
} }
return this.load( sourceMap ); return this.load( sourceMap );
} else { } else {
@@ -172,7 +172,7 @@
// FIXME: This changes the state of the I18N object, // FIXME: This changes the state of the I18N object,
// should probably not change the 'this.parser' but just // should probably not change the 'this.parser' but just
// pass it to the parser. // pass it to the parser.
this.parser.language = $.i18n.languages[$.i18n().locale] || $.i18n.languages['default']; this.parser.language = $.i18n.languages[ $.i18n().locale ] || $.i18n.languages[ 'default' ];
if ( message === '' ) { if ( message === '' ) {
message = key; message = key;
} }
@@ -262,7 +262,7 @@
parse: function ( message, parameters ) { parse: function ( message, parameters ) {
return message.replace( /\$(\d+)/g, function ( str, match ) { return message.replace( /\$(\d+)/g, function ( str, match ) {
var index = parseInt( match, 10 ) - 1; var index = parseInt( match, 10 ) - 1;
return parameters[index] !== undefined ? parameters[index] : '$' + match; return parameters[ index ] !== undefined ? parameters[ index ] : '$' + match;
} ); } );
}, },
emitter: {} emitter: {}

View File

@@ -285,13 +285,13 @@
// Handle for Explicit 0= & 1= values // Handle for Explicit 0= & 1= values
for ( index = 0; index < forms.length; index++ ) { for ( index = 0; index < forms.length; index++ ) {
form = forms[index]; form = forms[ index ];
if ( explicitPluralPattern.test( form ) ) { if ( explicitPluralPattern.test( form ) ) {
formCount = parseInt( form.substring( 0, form.indexOf( '=' ) ), 10 ); formCount = parseInt( form.substring( 0, form.indexOf( '=' ) ), 10 );
if ( formCount === count ) { if ( formCount === count ) {
return ( form.substr( form.indexOf( '=' ) + 1 ) ); return ( form.substr( form.indexOf( '=' ) + 1 ) );
} }
forms[index] = undefined; forms[ index ] = undefined;
} }
} }
@@ -301,17 +301,17 @@
} }
} ); } );
pluralRules = this.pluralRules[$.i18n().locale]; pluralRules = this.pluralRules[ $.i18n().locale ];
if ( !pluralRules ) { if ( !pluralRules ) {
// default fallback. // default fallback.
return ( count === 1 ) ? forms[0] : forms[1]; return ( count === 1 ) ? forms[ 0 ] : forms[ 1 ];
} }
pluralFormIndex = this.getPluralForm( count, pluralRules ); pluralFormIndex = this.getPluralForm( count, pluralRules );
pluralFormIndex = Math.min( pluralFormIndex, forms.length - 1 ); pluralFormIndex = Math.min( pluralFormIndex, forms.length - 1 );
return forms[pluralFormIndex]; return forms[ pluralFormIndex ];
}, },
/** /**
@@ -327,8 +327,8 @@
pluralFormIndex = 0; pluralFormIndex = 0;
for ( i = 0; i < pluralForms.length; i++ ) { for ( i = 0; i < pluralForms.length; i++ ) {
if ( pluralRules[pluralForms[i]] ) { if ( pluralRules[ pluralForms[ i ] ] ) {
if ( pluralRuleParser( pluralRules[pluralForms[i]], number ) ) { if ( pluralRuleParser( pluralRules[ pluralForms[ i ] ], number ) ) {
return pluralFormIndex; return pluralFormIndex;
} }
@@ -367,17 +367,17 @@
tmp = []; tmp = [];
for ( item in transformTable ) { for ( item in transformTable ) {
tmp[transformTable[item]] = item; tmp[ transformTable[ item ] ] = item;
} }
transformTable = tmp; transformTable = tmp;
} }
for ( i = 0; i < numberString.length; i++ ) { for ( i = 0; i < numberString.length; i++ ) {
if ( transformTable[numberString[i]] ) { if ( transformTable[ numberString[ i ] ] ) {
convertedNumber += transformTable[numberString[i]]; convertedNumber += transformTable[ numberString[ i ] ];
} else { } else {
convertedNumber += numberString[i]; convertedNumber += numberString[ i ];
} }
} }
@@ -418,18 +418,18 @@
} }
while ( forms.length < 2 ) { while ( forms.length < 2 ) {
forms.push( forms[forms.length - 1] ); forms.push( forms[ forms.length - 1 ] );
} }
if ( gender === 'male' ) { if ( gender === 'male' ) {
return forms[0]; return forms[ 0 ];
} }
if ( gender === 'female' ) { if ( gender === 'female' ) {
return forms[1]; return forms[ 1 ];
} }
return ( forms.length === 3 ) ? forms[2] : forms[0]; return ( forms.length === 3 ) ? forms[ 2 ] : forms[ 0 ];
}, },
/** /**
@@ -458,11 +458,11 @@
bo: '༠༡༢༣༤༥༦༧༨༩' // FIXME use iso 639 codes bo: '༠༡༢༣༤༥༦༧༨༩' // FIXME use iso 639 codes
}; };
if ( !tables[language] ) { if ( !tables[ language ] ) {
return false; return false;
} }
return tables[language].split( '' ); return tables[ language ].split( '' );
} }
}; };

View File

@@ -74,7 +74,7 @@
locale = key; locale = key;
// No {locale} given, assume data is a group of languages, // No {locale} given, assume data is a group of languages,
// call this function again for each language. // call this function again for each language.
deferreds.push( messageStore.load( source[key], locale ) ); deferreds.push( messageStore.load( source[ key ], locale ) );
} }
} }
return $.when.apply( $, deferreds ); return $.when.apply( $, deferreds );
@@ -89,10 +89,10 @@
* @param messages * @param messages
*/ */
set: function ( locale, messages ) { set: function ( locale, messages ) {
if ( !this.messages[locale] ) { if ( !this.messages[ locale ] ) {
this.messages[locale] = messages; this.messages[ locale ] = messages;
} else { } else {
this.messages[locale] = $.extend( this.messages[locale], messages ); this.messages[ locale ] = $.extend( this.messages[ locale ], messages );
} }
}, },
@@ -103,7 +103,7 @@
* @returns {Boolean} * @returns {Boolean}
*/ */
get: function ( locale, messageKey ) { get: function ( locale, messageKey ) {
return this.messages[locale] && this.messages[locale][messageKey]; return this.messages[ locale ] && this.messages[ locale ][ messageKey ];
} }
}; };

View File

@@ -18,7 +18,7 @@
var MessageParser = function ( options ) { var MessageParser = function ( options ) {
this.options = $.extend( {}, $.i18n.parser.defaults, options ); this.options = $.extend( {}, $.i18n.parser.defaults, options );
this.language = $.i18n.languages[String.locale] || $.i18n.languages['default']; this.language = $.i18n.languages[ String.locale ] || $.i18n.languages[ 'default' ];
this.emitter = $.i18n.parser.emitter; this.emitter = $.i18n.parser.emitter;
}; };
@@ -30,7 +30,7 @@
return message.replace( /\$(\d+)/g, function ( str, match ) { return message.replace( /\$(\d+)/g, function ( str, match ) {
var index = parseInt( match, 10 ) - 1; var index = parseInt( match, 10 ) - 1;
return parameters[index] !== undefined ? parameters[index] : '$' + match; return parameters[ index ] !== undefined ? parameters[ index ] : '$' + match;
} ); } );
}, },
@@ -39,8 +39,8 @@
return this.simpleParse( message, replacements ); return this.simpleParse( message, replacements );
} }
this.emitter.language = $.i18n.languages[$.i18n().locale] || this.emitter.language = $.i18n.languages[ $.i18n().locale ] ||
$.i18n.languages['default']; $.i18n.languages[ 'default' ];
return this.emitter.emit( this.ast( message ), replacements ); return this.emitter.emit( this.ast( message ), replacements );
}, },
@@ -58,7 +58,7 @@
var i, result; var i, result;
for ( i = 0; i < parserSyntax.length; i++ ) { for ( i = 0; i < parserSyntax.length; i++ ) {
result = parserSyntax[i](); result = parserSyntax[ i ]();
if ( result !== null ) { if ( result !== null ) {
return result; return result;
@@ -78,7 +78,7 @@
result = []; result = [];
for ( i = 0; i < parserSyntax.length; i++ ) { for ( i = 0; i < parserSyntax.length; i++ ) {
res = parserSyntax[i](); res = parserSyntax[ i ]();
if ( res === null ) { if ( res === null ) {
pos = originalPos; pos = originalPos;
@@ -140,9 +140,9 @@
return null; return null;
} }
pos += matches[0].length; pos += matches[ 0 ].length;
return matches[0]; return matches[ 0 ];
}; };
} }
@@ -189,7 +189,7 @@
function escapedLiteral() { function escapedLiteral() {
var result = sequence( [ backslash, anyCharacter ] ); var result = sequence( [ backslash, anyCharacter ] );
return result === null ? null : result[1]; return result === null ? null : result[ 1 ];
} }
choice( [ escapedLiteral, regularLiteralWithoutSpace ] ); choice( [ escapedLiteral, regularLiteralWithoutSpace ] );
@@ -203,7 +203,7 @@
return null; return null;
} }
return [ 'REPLACE', parseInt( result[1], 10 ) - 1 ]; return [ 'REPLACE', parseInt( result[ 1 ], 10 ) - 1 ];
} }
templateName = transform( templateName = transform(
@@ -224,23 +224,23 @@
return null; return null;
} }
expr = result[1]; expr = result[ 1 ];
// use a "CONCAT" operator if there are multiple nodes, // use a "CONCAT" operator if there are multiple nodes,
// otherwise return the first node, raw. // otherwise return the first node, raw.
return expr.length > 1 ? [ 'CONCAT' ].concat( expr ) : expr[0]; return expr.length > 1 ? [ 'CONCAT' ].concat( expr ) : expr[ 0 ];
} }
function templateWithReplacement() { function templateWithReplacement() {
var result = sequence( [ templateName, colon, replacement ] ); var result = sequence( [ templateName, colon, replacement ] );
return result === null ? null : [ result[0], result[2] ]; return result === null ? null : [ result[ 0 ], result[ 2 ] ];
} }
function templateWithOutReplacement() { function templateWithOutReplacement() {
var result = sequence( [ templateName, colon, paramExpression ] ); var result = sequence( [ templateName, colon, paramExpression ] );
return result === null ? null : [ result[0], result[2] ]; return result === null ? null : [ result[ 0 ], result[ 2 ] ];
} }
templateContents = choice( [ templateContents = choice( [
@@ -254,7 +254,7 @@
nOrMore( 0, templateParam ) nOrMore( 0, templateParam )
] ); ] );
return res === null ? null : res[0].concat( res[1] ); return res === null ? null : res[ 0 ].concat( res[ 1 ] );
}, },
function () { function () {
var res = sequence( [ templateName, nOrMore( 0, templateParam ) ] ); var res = sequence( [ templateName, nOrMore( 0, templateParam ) ] );
@@ -263,7 +263,7 @@
return null; return null;
} }
return [ res[0] ].concat( res[1] ); return [ res[ 0 ] ].concat( res[ 1 ] );
} }
] ); ] );
@@ -273,7 +273,7 @@
function template() { function template() {
var result = sequence( [ openTemplate, templateContents, closeTemplate ] ); var result = sequence( [ openTemplate, templateContents, closeTemplate ] );
return result === null ? null : result[1]; return result === null ? null : result[ 1 ];
} }
expression = choice( [ template, replacement, literal ] ); expression = choice( [ template, replacement, literal ] );

View File

@@ -4,7 +4,7 @@
( function ( $ ) { ( function ( $ ) {
'use strict'; 'use strict';
$.i18n.languages.bs = $.extend( {}, $.i18n.languages['default'], { $.i18n.languages.bs = $.extend( {}, $.i18n.languages[ 'default' ], {
convertGrammar: function ( word, form ) { convertGrammar: function ( word, form ) {
switch ( form ) { switch ( form ) {
case 'instrumental': // instrumental case 'instrumental': // instrumental

View File

@@ -4,7 +4,7 @@
( function ( $ ) { ( function ( $ ) {
'use strict'; 'use strict';
$.i18n.languages.dsb = $.extend( {}, $.i18n.languages['default'], { $.i18n.languages.dsb = $.extend( {}, $.i18n.languages[ 'default' ], {
convertGrammar: function ( word, form ) { convertGrammar: function ( word, form ) {
switch ( form ) { switch ( form ) {
case 'instrumental': // instrumental case 'instrumental': // instrumental

View File

@@ -7,7 +7,7 @@
( function ( $ ) { ( function ( $ ) {
'use strict'; 'use strict';
$.i18n.languages.fi = $.extend( {}, $.i18n.languages['default'], { $.i18n.languages.fi = $.extend( {}, $.i18n.languages[ 'default' ], {
convertGrammar: function ( word, form ) { convertGrammar: function ( word, form ) {
// vowel harmony flag // vowel harmony flag
var aou = word.match( /[aou][^äöy]*$/i ), var aou = word.match( /[aou][^äöy]*$/i ),

View File

@@ -4,7 +4,7 @@
( function ( $ ) { ( function ( $ ) {
'use strict'; 'use strict';
$.i18n.languages.ga = $.extend( {}, $.i18n.languages['default'], { $.i18n.languages.ga = $.extend( {}, $.i18n.languages[ 'default' ], {
convertGrammar: function ( word, form ) { convertGrammar: function ( word, form ) {
if ( form === 'ainmlae' ) { if ( form === 'ainmlae' ) {
switch ( word ) { switch ( word ) {

View File

@@ -4,7 +4,7 @@
( function ( $ ) { ( function ( $ ) {
'use strict'; 'use strict';
$.i18n.languages.he = $.extend( {}, $.i18n.languages['default'], { $.i18n.languages.he = $.extend( {}, $.i18n.languages[ 'default' ], {
convertGrammar: function ( word, form ) { convertGrammar: function ( word, form ) {
switch ( form ) { switch ( form ) {
case 'prefixed': case 'prefixed':

View File

@@ -4,7 +4,7 @@
( function ( $ ) { ( function ( $ ) {
'use strict'; 'use strict';
$.i18n.languages.hsb = $.extend( {}, $.i18n.languages['default'], { $.i18n.languages.hsb = $.extend( {}, $.i18n.languages[ 'default' ], {
convertGrammar: function ( word, form ) { convertGrammar: function ( word, form ) {
switch ( form ) { switch ( form ) {
case 'instrumental': // instrumental case 'instrumental': // instrumental

View File

@@ -6,7 +6,7 @@
( function ( $ ) { ( function ( $ ) {
'use strict'; 'use strict';
$.i18n.languages.hu = $.extend( {}, $.i18n.languages['default'], { $.i18n.languages.hu = $.extend( {}, $.i18n.languages[ 'default' ], {
convertGrammar: function ( word, form ) { convertGrammar: function ( word, form ) {
switch ( form ) { switch ( form ) {
case 'rol': case 'rol':

View File

@@ -5,7 +5,7 @@
( function ( $ ) { ( function ( $ ) {
'use strict'; 'use strict';
$.i18n.languages.hy = $.extend( {}, $.i18n.languages['default'], { $.i18n.languages.hy = $.extend( {}, $.i18n.languages[ 'default' ], {
convertGrammar: function ( word, form ) { convertGrammar: function ( word, form ) {
if ( form === 'genitive' ) { // սեռական հոլով if ( form === 'genitive' ) { // սեռական հոլով
if ( word.substr( -1 ) === 'ա' ) { if ( word.substr( -1 ) === 'ա' ) {

View File

@@ -7,7 +7,7 @@
( function ( $ ) { ( function ( $ ) {
'use strict'; 'use strict';
$.i18n.languages.la = $.extend( {}, $.i18n.languages['default'], { $.i18n.languages.la = $.extend( {}, $.i18n.languages[ 'default' ], {
convertGrammar: function ( word, form ) { convertGrammar: function ( word, form ) {
switch ( form ) { switch ( form ) {
case 'genitive': case 'genitive':

View File

@@ -7,7 +7,7 @@
( function ( $ ) { ( function ( $ ) {
'use strict'; 'use strict';
$.i18n.languages.ml = $.extend( {}, $.i18n.languages['default'], { $.i18n.languages.ml = $.extend( {}, $.i18n.languages[ 'default' ], {
convertGrammar: function ( word, form ) { convertGrammar: function ( word, form ) {
form = form.toLowerCase(); form = form.toLowerCase();
switch ( form ) { switch ( form ) {

View File

@@ -7,7 +7,7 @@
( function ( $ ) { ( function ( $ ) {
'use strict'; 'use strict';
$.i18n.languages.os = $.extend( {}, $.i18n.languages['default'], { $.i18n.languages.os = $.extend( {}, $.i18n.languages[ 'default' ], {
convertGrammar: function ( word, form ) { convertGrammar: function ( word, form ) {
var endAllative, jot, hyphen, ending; var endAllative, jot, hyphen, ending;

View File

@@ -5,7 +5,7 @@
( function ( $ ) { ( function ( $ ) {
'use strict'; 'use strict';
$.i18n.languages.ru = $.extend( {}, $.i18n.languages['default'], { $.i18n.languages.ru = $.extend( {}, $.i18n.languages[ 'default' ], {
convertGrammar: function ( word, form ) { convertGrammar: function ( word, form ) {
if ( form === 'genitive' ) { // родительный падеж if ( form === 'genitive' ) { // родительный падеж
if ( word.substr( -1 ) === 'ь' ) { if ( word.substr( -1 ) === 'ь' ) {

View File

@@ -5,7 +5,7 @@
( function ( $ ) { ( function ( $ ) {
'use strict'; 'use strict';
$.i18n.languages.sl = $.extend( {}, $.i18n.languages['default'], { $.i18n.languages.sl = $.extend( {}, $.i18n.languages[ 'default' ], {
convertGrammar: function ( word, form ) { convertGrammar: function ( word, form ) {
switch ( form ) { switch ( form ) {
// locative // locative

View File

@@ -5,7 +5,7 @@
( function ( $ ) { ( function ( $ ) {
'use strict'; 'use strict';
$.i18n.languages.uk = $.extend( {}, $.i18n.languages['default'], { $.i18n.languages.uk = $.extend( {}, $.i18n.languages[ 'default' ], {
convertGrammar: function ( word, form ) { convertGrammar: function ( word, form ) {
switch ( form ) { switch ( form ) {
case 'genitive': // родовий відмінок case 'genitive': // родовий відмінок