Avoid 404s in non-localized locales

* Update jquery.i18n - if messageLocationResolver returns false for
  a locale, no server hit will be attempted
* Refactor i18n preparation code to a new method
* Use the ULS RL hooks to find out to which locales it is localized,
  pass that list to js to avoid hitting server.
* Also avoid directory scanning in each request by putting
  the locale list in cache

Fixes Bug 41454

Change-Id: I0c923b35db01b884e2dd55873dd5fb7384434645
This commit is contained in:
Santhosh Thottingal
2012-10-27 19:27:10 +05:30
committed by Gerrit Code Review
parent b86724b811
commit 427c94dbbf
3 changed files with 75 additions and 20 deletions

View File

@@ -90,26 +90,49 @@
return unique;
};
$( document ).ready( function () {
var extensionPath, i18n, $ulsTrigger, previousLanguages, previousLang;
/**
* i18n initialization
*/
function i18nInit () {
var extensionPath, locales, i18n;
extensionPath = mw.config.get( 'wgExtensionAssetsPath' )
+ '/UniversalLanguageSelector/';
// i18n initialization
+ '/UniversalLanguageSelector/';
locales = mw.config.get( 'wgULSi18nLocales' );
i18n = $.i18n( {
locale: currentLang,
messageLocationResolver: function ( locale ) {
return extensionPath + 'i18n/' + locale + '.json';
messageLocationResolver: function ( locale, messageKey ) {
// Namespaces are not available in jquery.i18n yet. Developers prefix
// the message key with a unique namespace like ext-uls-*
if ( messageKey.indexOf( 'uls' ) === 0 ) {
if ( $.inArray( locale, locales['uls'] ) >= 0 ) {
return extensionPath + 'lib/jquery.uls/i18n/' + locale + '.json';
}
return false;
}
if ( messageKey.indexOf( 'ext-uls' ) === 0 ) {
if ( $.inArray( locale, locales['ext-uls'] ) >= 0 ) {
return extensionPath + 'i18n/' + locale + '.json';
}
return false;
}
}
} );
// localization for jquery.uls
i18n.load( extensionPath + 'lib/jquery.uls/i18n/' + currentLang + '.json', currentLang );
// localization for jquery.uls- fallback locale
i18n.load( extensionPath + 'lib/jquery.uls/i18n/en.json', 'en' );
// localization for mediaWiki ULS
i18n.load( extensionPath + 'i18n/' + currentLang + '.json', currentLang );
// localization for mediaWiki ULS- fallback locale
// localization for mediaWiki ULS - fallback locale
i18n.load( extensionPath + 'i18n/en.json', 'en' );
}
$( document ).ready( function () {
var $ulsTrigger, previousLanguages, previousLang;
// JavaScript side i18n initialization
i18nInit();
$ulsTrigger = $( '.uls-trigger' );
previousLanguages = mw.uls.getPreviousLanguages() || [];