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:
@@ -316,11 +316,9 @@
|
||||
* @param {String} language Language code
|
||||
*/
|
||||
preview: function ( language ) {
|
||||
var displaySettings = this,
|
||||
i18n = $.i18n();
|
||||
var displaySettings = this;
|
||||
|
||||
i18n.locale = language;
|
||||
i18n.messageStore.load( i18n.locale ).done( function () {
|
||||
mw.uls.loadLocalization( language ).done( function () {
|
||||
displaySettings.i18n();
|
||||
} );
|
||||
},
|
||||
|
||||
@@ -17,54 +17,31 @@
|
||||
* @licence MIT License
|
||||
*/
|
||||
|
||||
( function ( $, mw, undefined ) {
|
||||
( function ( $, mw ) {
|
||||
'use strict';
|
||||
|
||||
mw.uls = mw.uls || {};
|
||||
|
||||
// jquery.i18n has CLDRPluralRuleParser but MediaWiki also has the same
|
||||
// parser. Reuse it by aliasing it to window.pluralRuleParser
|
||||
window.pluralRuleParser = mw.libs.pluralRuleParser;
|
||||
|
||||
/**
|
||||
* jquery.i18n message store for MediaWiki
|
||||
*
|
||||
*/
|
||||
var MWMessageStore = function () {
|
||||
this.messages = {};
|
||||
};
|
||||
// JavaScript side i18n initialization
|
||||
$.i18n( {
|
||||
locale: mw.config.get( 'wgUserLanguage' )
|
||||
} );
|
||||
|
||||
MWMessageStore.prototype = {
|
||||
init: function () {},
|
||||
mw.uls.loadLocalization = function ( locale ) {
|
||||
var i18n = $.i18n();
|
||||
|
||||
get: function ( locale, messageKey ) {
|
||||
return ( this.isLoaded( locale ) && this.messages[locale][messageKey] ) ||
|
||||
'<' + messageKey + '>';
|
||||
},
|
||||
|
||||
set: function( locale, messages ) {
|
||||
this.messages[locale] = messages;
|
||||
},
|
||||
|
||||
isLoaded: function ( locale ) {
|
||||
return this.messages[locale];
|
||||
},
|
||||
|
||||
load: function ( locale ) {
|
||||
var store = this,
|
||||
deferred = $.Deferred(),
|
||||
url = mw.util.wikiScript( 'api' ) + '?action=ulslocalization&language=';
|
||||
|
||||
if ( store.isLoaded( locale ) ) {
|
||||
return deferred.resolve();
|
||||
}
|
||||
|
||||
deferred = $.getJSON( url + locale ).done( function ( data ) {
|
||||
store.set( locale, data );
|
||||
} ).fail( function ( jqxhr, settings, exception ) {
|
||||
mw.log( 'Error in loading messages from ' + url + ' Exception: ' + exception );
|
||||
} );
|
||||
return deferred.promise();
|
||||
i18n.locale = locale;
|
||||
if ( i18n.messageStore.messages[locale] ) {
|
||||
return $.Deferred().resolve();
|
||||
}
|
||||
return i18n.load(
|
||||
mw.util.wikiScript( 'api' ) + '?action=ulslocalization&language=' + locale,
|
||||
locale
|
||||
);
|
||||
};
|
||||
mw.uls = mw.uls || {};
|
||||
mw.uls.messageStore = new MWMessageStore();
|
||||
|
||||
}( jQuery, mediaWiki ) );
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
this.$languageFilter.addClass( 'noime' );
|
||||
};
|
||||
|
||||
var jsonLoader,
|
||||
var jsonLoader = null,
|
||||
initialized = false,
|
||||
currentLang = mw.config.get( 'wgUserLanguage' ),
|
||||
logEventQueue = $.Callbacks( 'memory once' );
|
||||
@@ -211,14 +211,8 @@
|
||||
*/
|
||||
$.uls.data.addLanguage( 'als', { target: 'gsw' } );
|
||||
|
||||
// JavaScript side i18n initialization
|
||||
$.i18n( {
|
||||
locale: currentLang,
|
||||
messageStore: mw.uls.messageStore
|
||||
} );
|
||||
|
||||
if ( !jsonLoader ) {
|
||||
jsonLoader = mw.uls.messageStore.load( currentLang );
|
||||
jsonLoader = mw.uls.loadLocalization( currentLang );
|
||||
} else {
|
||||
jsonLoader.done( function () {
|
||||
initialized = true;
|
||||
|
||||
Reference in New Issue
Block a user