Update jquery.i18n from upstream

Upstream: https://github.com/wikimedia/jquery.i18n
Upstream changes:
* Fixed a potential js error because of wrong logic
* Fixed some JShint errors
* Added license and credits files
* Updated gitignore file
* Fixed uk and ru grammar rules and updating tests
* Source code formatting updates

Change-Id: I43433cc3d9993045160dc85ed9e73370d22794cf
This commit is contained in:
Santhosh Thottingal
2013-11-08 16:08:54 +05:30
parent fca6e1b17b
commit 42deb56323
9 changed files with 97 additions and 81 deletions

View File

@@ -40,16 +40,15 @@
* String.prototype.toLocaleString and String.locale.
*/
init: function () {
var i18n;
var i18n = this;
i18n = this;
// Set locale of String environment
String.locale = i18n.locale;
// Override String.localeString method
String.prototype.toLocaleString = function () {
var localeParts, localePartIndex, value, locale, fallbackIndex,
_locale, message;
tryingLocale, message;
value = this.valueOf();
locale = i18n.locale;
@@ -62,11 +61,13 @@
localePartIndex = localeParts.length;
do {
_locale = localeParts.slice( 0, localePartIndex ).join( '-' );
message = i18n.messageStore.get( _locale, value );
tryingLocale = localeParts.slice( 0, localePartIndex ).join( '-' );
message = i18n.messageStore.get( tryingLocale, value );
if ( message ) {
return message;
}
localePartIndex--;
} while ( localePartIndex );
@@ -118,12 +119,12 @@
},
/**
* Does parameter and magic word substitution.
*
* @param {string} key Message key
* @param {Array} parameters Message parameters
* @return {string}
*/
* Does parameter and magic word substitution.
*
* @param {string} key Message key
* @param {Array} parameters Message parameters
* @return {string}
*/
parse: function ( key, parameters ) {
var message = key.toLocaleString();
// FIXME: This changes the state of the I18N object,
@@ -137,16 +138,15 @@
}
};
/**
* Process a message from the $.I18N instance
* for the current document, stored in jQuery.data(document).
*
* @param {string} key Key of the message.
* @param {string} param1 [param...] Variadic list of parameters for {key}.
* @return {string|$.I18N} Parsed message, or if no key was given
* the instance of $.I18N is returned.
*/
* Process a message from the $.I18N instance
* for the current document, stored in jQuery.data(document).
*
* @param {string} key Key of the message.
* @param {string} param1 [param...] Variadic list of parameters for {key}.
* @return {string|$.I18N} Parsed message, or if no key was given
* the instance of $.I18N is returned.
*/
$.i18n = function ( key, param1 ) {
var parameters,
i18n = $.data( document, 'i18n' ),
@@ -184,12 +184,12 @@
$.fn.i18n = function () {
var i18n = $.data( document, 'i18n' );
String.locale = i18n.locale;
if ( !i18n ) {
i18n = new I18N();
$.data( document, 'i18n', i18n );
}
String.locale = i18n.locale;
return this.each( function () {
var $this = $( this ),
messageKey = $this.data( 'i18n' );
@@ -225,7 +225,7 @@
},
emitter: {}
};
$.i18n.fallbacks = {};
$.i18n.debug = false;
$.i18n.log = function ( /* arguments */ ) {
if ( window.console && $.i18n.debug ) {