Update jquery.i18n from upstream, use its default message store
In Iddef0805ab a custom message store was introduced for ULS, but there were updates in jquery.i18n that allows us to use default message store again. (see https://github.com/wikimedia/jquery.i18n/pull/40) Change-Id: I86cb7a44efa83e5811824cd1104c6be11b1e2925
This commit is contained in:
@@ -16,13 +16,13 @@
|
||||
( function ( $ ) {
|
||||
'use strict';
|
||||
|
||||
var nav,
|
||||
var nav, I18N,
|
||||
slice = Array.prototype.slice;
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Object} options
|
||||
*/
|
||||
var I18N = function ( options ) {
|
||||
I18N = function ( options ) {
|
||||
// Load defaults
|
||||
this.options = $.extend( {}, I18N.defaults, options );
|
||||
|
||||
@@ -43,13 +43,13 @@
|
||||
var i18n;
|
||||
|
||||
i18n = this;
|
||||
i18n.messageStore.init( i18n.locale );
|
||||
// Set locale of String environment
|
||||
String.locale = i18n.locale;
|
||||
|
||||
// Override String.localeString method
|
||||
String.prototype.toLocaleString = function () {
|
||||
var localeParts, messageLocation, localePartIndex, value, locale, fallbackIndex;
|
||||
var localeParts, localePartIndex, value, locale, fallbackIndex,
|
||||
_locale, message;
|
||||
|
||||
value = this.valueOf();
|
||||
locale = i18n.locale;
|
||||
@@ -62,24 +62,11 @@
|
||||
localePartIndex = localeParts.length;
|
||||
|
||||
do {
|
||||
var _locale = localeParts.slice( 0, localePartIndex ).join( '-' );
|
||||
|
||||
if ( i18n.options.messageLocationResolver ) {
|
||||
messageLocation = i18n.options.messageLocationResolver( _locale, value );
|
||||
|
||||
if ( messageLocation &&
|
||||
( !i18n.messageStore.isLoaded( _locale ,messageLocation ) )
|
||||
) {
|
||||
i18n.messageStore.load( messageLocation, _locale );
|
||||
}
|
||||
}
|
||||
|
||||
var message = i18n.messageStore.get( _locale, value );
|
||||
|
||||
_locale = localeParts.slice( 0, localePartIndex ).join( '-' );
|
||||
message = i18n.messageStore.get( _locale, value );
|
||||
if ( message ) {
|
||||
return message;
|
||||
}
|
||||
|
||||
localePartIndex--;
|
||||
} while ( localePartIndex );
|
||||
|
||||
@@ -89,7 +76,7 @@
|
||||
|
||||
locale = ( $.i18n.fallbacks[i18n.locale] && $.i18n.fallbacks[i18n.locale][fallbackIndex] ) ||
|
||||
i18n.options.fallbackLocale;
|
||||
i18n.log( 'Trying fallback locale for ' + i18n.locale + ': ' + locale );
|
||||
$.i18n.log( 'Trying fallback locale for ' + i18n.locale + ': ' + locale );
|
||||
|
||||
fallbackIndex++;
|
||||
}
|
||||
@@ -122,17 +109,12 @@
|
||||
* null/undefined/false,
|
||||
* all cached messages for the i18n instance will get reset.
|
||||
*
|
||||
* @param {String|Object|null} data
|
||||
* @param {String|Object} source
|
||||
* @param {String} locale Language tag
|
||||
* @returns {jQuery.Promise}
|
||||
*/
|
||||
load: function ( data, locale ) {
|
||||
this.messageStore.load( data, locale );
|
||||
},
|
||||
|
||||
log: function ( /* arguments */ ) {
|
||||
if ( window.console && $.i18n.debug ) {
|
||||
window.console.log.apply( window.console, arguments );
|
||||
}
|
||||
load: function ( source, locale ) {
|
||||
return this.messageStore.load( source, locale );
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -204,18 +186,16 @@
|
||||
var i18n = $.data( document, 'i18n' );
|
||||
String.locale = i18n.locale;
|
||||
if ( !i18n ) {
|
||||
i18n = new I18N( );
|
||||
i18n = new I18N();
|
||||
$.data( document, 'i18n', i18n );
|
||||
}
|
||||
return this.each( function () {
|
||||
var $this = $( this );
|
||||
|
||||
if ( $this.data( 'i18n' ) ) {
|
||||
var messageKey = $this.data( 'i18n' ),
|
||||
message = messageKey.toLocaleString();
|
||||
if ( message !== '' ) {
|
||||
$this.text( message );
|
||||
}
|
||||
return this.each( function () {
|
||||
var $this = $( this ),
|
||||
messageKey = $this.data( 'i18n' );
|
||||
|
||||
if ( messageKey ) {
|
||||
$this.text( i18n.parse( messageKey ) );
|
||||
} else {
|
||||
$this.find( '[data-i18n]' ).i18n();
|
||||
}
|
||||
@@ -247,19 +227,19 @@
|
||||
};
|
||||
|
||||
$.i18n.debug = false;
|
||||
|
||||
$.i18n.log = function ( /* arguments */ ) {
|
||||
if ( window.console && $.i18n.debug ) {
|
||||
window.console.log.apply( window.console, arguments );
|
||||
}
|
||||
};
|
||||
/* Static members */
|
||||
I18N.defaults = {
|
||||
locale: String.locale,
|
||||
fallbackLocale: 'en',
|
||||
parser: $.i18n.parser,
|
||||
messageStore: $.i18n.messageStore,
|
||||
/* messageLocationResolver - should be a function taking language code as argument and
|
||||
* returning absolute or relative path to the localization file
|
||||
*/
|
||||
messageLocationResolver: null
|
||||
messageStore: $.i18n.messageStore
|
||||
};
|
||||
|
||||
// Expose constructor
|
||||
$.I18N = I18N;
|
||||
$.i18n.constructor = I18N;
|
||||
}( jQuery ) );
|
||||
|
||||
Reference in New Issue
Block a user