Update jquery.i18n from upstream

Upstream: https://github.com/wikimedia/jquery.i18n
Changes:
 * Support fallback loading when folder is passed as source to load
 * Do not overwrite existing messages for a locale while adding messages
   second time
 * Fix the country code case issue
 * Renamed jquery.i18n.messages.js to jquery.i18n.messagestore
 * ULS: Updated Resources.php for renaming of jquery.i18n.messages file

Change-Id: I60a6e3224cb7b8ea813a8ccd7e389071b3d1244c
This commit is contained in:
Kartik Mistry
2014-01-13 12:04:08 +05:30
parent 5f57b41101
commit 9c40252a72
4 changed files with 258 additions and 457 deletions

View File

@@ -57,7 +57,7 @@
while ( locale ) {
// Iterate through locales starting at most-specific until
// localization is found. As in fi-Latn-FI, fi-Latn and fi.
localeParts = locale.toLowerCase().split( '-' );
localeParts = locale.split( '-' );
localePartIndex = localeParts.length;
do {
@@ -96,18 +96,40 @@
/**
* General message loading API This can take a URL string for
* the json formatted messages.
* the json formatted messages. Example:
* <code>load('path/to/all_localizations.json');</code>
*
* This can also load a localization file for a locale <code>
* To load a localization file for a locale:
* <code>
* load('path/to/de-messages.json', 'de' );
* </code>
*
* To load a localization file from a directory:
* <code>
* load('path/to/i18n/directory', 'de' );
* </code>
* The above method has the advantage of fallback resolution.
* ie, it will automatically load the fallback locales for de.
* For most usecases, this is the recommended method.
* It is optional to have trailing slash at end.
*
* A data object containing message key- message translation mappings
* can also be passed Eg:
* can also be passed. Example:
* <code>
* load( { 'hello' : 'Hello' }, optionalLocale );
* </code> If the data argument is
* null/undefined/false,
* </code>
*
* A source map containing key-value pair of languagename and locations
* can also be passed. Example:
* <code>
* load( {
* 'bn': 'i18n/bn.json',
* 'he': 'i18n/he.json',
* 'en': 'i18n/en.json'
* } )
* </code>
*
* If the data argument is null/undefined/false,
* all cached messages for the i18n instance will get reset.
*
* @param {String|Object} source
@@ -115,7 +137,22 @@
* @returns {jQuery.Promise}
*/
load: function ( source, locale ) {
return this.messageStore.load( source, locale );
var fallbackLocales, locIndex, fallbackLocale, sourceMap = {};
if ( typeof source === 'string' &&
source.split('.').pop() !== 'json'
) {
fallbackLocales = ( $.i18n.fallbacks[locale] || [] )
.concat( this.options.fallbackLocale );
for ( locIndex in fallbackLocales ) {
fallbackLocale = fallbackLocales[locIndex];
sourceMap[fallbackLocale] = source + '/' + fallbackLocale + '.json';
}
return this.load( sourceMap );
} else {
return this.messageStore.load( source, locale );
}
},
/**