Remove jquery.i18n code that the ULS extension overrides

Instead of using the whole jquery.i18n code, use only required parts
that are not customized in MW ULS. For this define a new RL module
ext.uls.i18n.

Also refactor MW message store for jquery.i18n.

Change-Id: Idda9fe505428ade409d937314d7216ebb4232c36
This commit is contained in:
Santhosh Thottingal
2013-07-12 14:34:31 +05:30
committed by Amire80
parent a14f941f48
commit 28154206bf
24 changed files with 2538 additions and 2620 deletions

View File

@@ -0,0 +1,70 @@
/**
* ULS i18n preparation using jquery.i18n library
*
* Copyright (C) 2012-2013 Alolita Sharma, Amir Aharoni, Arun Ganesh, Brandon Harris,
* Niklas Laxström, Pau Giner, Santhosh Thottingal, Siebrand Mazeland and other
* contributors. See CREDITS for a list.
*
* UniversalLanguageSelector is dual licensed GPLv2 or later and MIT. You don't
* have to do anything special to choose one license or the other and you don't
* have to notify anyone which license you are using. You are free to use
* UniversalLanguageSelector in commercial projects as long as the copyright
* header is left intact. See files GPL-LICENSE and MIT-LICENSE for details.
*
* @file
* @ingroup Extensions
* @licence GNU General Public Licence 2.0 or later
* @licence MIT License
*/
( function ( $, mw, undefined ) {
'use strict';
// 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 = {};
};
MWMessageStore.prototype = {
init: function () {},
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();
}
};
mw.uls = mw.uls || {};
mw.uls.messageStore = new MWMessageStore();
}( jQuery, mediaWiki ) );

View File

@@ -31,8 +31,7 @@
this.$languageFilter.addClass( 'noime' );
};
var MWMessageStore,
jsonLoader,
var jsonLoader,
initialized = false,
currentLang = mw.config.get( 'wgUserLanguage' ),
logEventQueue = $.Callbacks( 'memory once' );
@@ -164,55 +163,12 @@
} );
};
/**
* jquery.i18n message store for MediaWiki
*
*/
MWMessageStore = function () {
this.messages = {};
};
MWMessageStore.prototype = {
init: function () {},
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();
}
};
/**
* Initialize ULS front-end and its i18n.
*
* @param {Function} callback callback function to be called after initialization.
*/
mw.uls.init = function ( callback ) {
var messageStore = new MWMessageStore();
callback = callback || $.noop;
@@ -255,11 +211,11 @@
// JavaScript side i18n initialization
$.i18n( {
locale: currentLang,
messageStore: messageStore
messageStore: mw.uls.messageStore
} );
if ( !jsonLoader ) {
jsonLoader = messageStore.load( currentLang );
jsonLoader = mw.uls.messageStore.load( currentLang );
} else {
jsonLoader.done( function () {
initialized = true;