|
|
@ -1,8 +1,7 @@ |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @preserve jed.js 1.1.0 https://github.com/SlexAxton/Jed
|
|
|
|
|
|
|
|
*/ |
|
|
|
/* |
|
|
|
/* |
|
|
|
jed.js |
|
|
|
|
|
|
|
v0.5.4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
https://github.com/SlexAxton/Jed
|
|
|
|
|
|
|
|
----------- |
|
|
|
----------- |
|
|
|
A gettext compatible i18n library for modern JavaScript Applications |
|
|
|
A gettext compatible i18n library for modern JavaScript Applications |
|
|
|
|
|
|
|
|
|
|
@ -91,7 +90,9 @@ in order to offer easy upgrades -- jsgettext.berlios.de |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
// The default domain if one is missing
|
|
|
|
// The default domain if one is missing
|
|
|
|
"domain" : "messages" |
|
|
|
"domain" : "messages", |
|
|
|
|
|
|
|
// enable debug mode to log untranslated strings to the console
|
|
|
|
|
|
|
|
"debug" : false |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Mix in the sent options with the default options
|
|
|
|
// Mix in the sent options with the default options
|
|
|
@ -136,7 +137,7 @@ in order to offer easy upgrades -- jsgettext.berlios.de |
|
|
|
}, |
|
|
|
}, |
|
|
|
fetch : function ( sArr ) { |
|
|
|
fetch : function ( sArr ) { |
|
|
|
if ( {}.toString.call( sArr ) != '[object Array]' ) { |
|
|
|
if ( {}.toString.call( sArr ) != '[object Array]' ) { |
|
|
|
sArr = [].slice.call(arguments); |
|
|
|
sArr = [].slice.call(arguments, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
return ( sArr && sArr.length ? Jed.sprintf : function(x){ return x; } )( |
|
|
|
return ( sArr && sArr.length ? Jed.sprintf : function(x){ return x; } )( |
|
|
|
this._i18n.dcnpgettext(this._domain, this._context, this._key, this._pkey, this._val), |
|
|
|
this._i18n.dcnpgettext(this._domain, this._context, this._key, this._pkey, this._val), |
|
|
@ -221,9 +222,6 @@ in order to offer easy upgrades -- jsgettext.berlios.de |
|
|
|
// isn't explicitly passed in
|
|
|
|
// isn't explicitly passed in
|
|
|
|
domain = domain || this._textdomain; |
|
|
|
domain = domain || this._textdomain; |
|
|
|
|
|
|
|
|
|
|
|
// Default the value to the singular case
|
|
|
|
|
|
|
|
val = typeof val == 'undefined' ? 1 : val; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var fallback; |
|
|
|
var fallback; |
|
|
|
|
|
|
|
|
|
|
|
// Handle special cases
|
|
|
|
// Handle special cases
|
|
|
@ -257,6 +255,22 @@ in order to offer easy upgrades -- jsgettext.berlios.de |
|
|
|
throw new Error('No translation key found.'); |
|
|
|
throw new Error('No translation key found.'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var key = context ? context + Jed.context_delimiter + singular_key : singular_key, |
|
|
|
|
|
|
|
locale_data = this.options.locale_data, |
|
|
|
|
|
|
|
dict = locale_data[ domain ], |
|
|
|
|
|
|
|
defaultConf = (locale_data.messages || this.defaults.locale_data.messages)[""], |
|
|
|
|
|
|
|
pluralForms = dict[""].plural_forms || dict[""]["Plural-Forms"] || dict[""]["plural-forms"] || defaultConf.plural_forms || defaultConf["Plural-Forms"] || defaultConf["plural-forms"], |
|
|
|
|
|
|
|
val_list, |
|
|
|
|
|
|
|
res; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var val_idx; |
|
|
|
|
|
|
|
if (val === undefined) { |
|
|
|
|
|
|
|
// No value passed in; assume singular key lookup.
|
|
|
|
|
|
|
|
val_idx = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// Value has been passed in; use plural-forms calculations.
|
|
|
|
|
|
|
|
|
|
|
|
// Handle invalid numbers, but try casting strings for good measure
|
|
|
|
// Handle invalid numbers, but try casting strings for good measure
|
|
|
|
if ( typeof val != 'number' ) { |
|
|
|
if ( typeof val != 'number' ) { |
|
|
|
val = parseInt( val, 10 ); |
|
|
|
val = parseInt( val, 10 ); |
|
|
@ -266,13 +280,8 @@ in order to offer easy upgrades -- jsgettext.berlios.de |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var key = context ? context + Jed.context_delimiter + singular_key : singular_key, |
|
|
|
val_idx = getPluralFormFunc(pluralForms)(val); |
|
|
|
locale_data = this.options.locale_data, |
|
|
|
} |
|
|
|
dict = locale_data[ domain ], |
|
|
|
|
|
|
|
pluralForms = dict[""].plural_forms || (locale_data.messages || this.defaults.locale_data.messages)[""].plural_forms, |
|
|
|
|
|
|
|
val_idx = getPluralFormFunc(pluralForms)(val) + 1, |
|
|
|
|
|
|
|
val_list, |
|
|
|
|
|
|
|
res; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Throw an error if a domain isn't found
|
|
|
|
// Throw an error if a domain isn't found
|
|
|
|
if ( ! dict ) { |
|
|
|
if ( ! dict ) { |
|
|
@ -283,20 +292,25 @@ in order to offer easy upgrades -- jsgettext.berlios.de |
|
|
|
|
|
|
|
|
|
|
|
// If there is no match, then revert back to
|
|
|
|
// If there is no match, then revert back to
|
|
|
|
// english style singular/plural with the keys passed in.
|
|
|
|
// english style singular/plural with the keys passed in.
|
|
|
|
if ( ! val_list || val_idx >= val_list.length ) { |
|
|
|
if ( ! val_list || val_idx > val_list.length ) { |
|
|
|
if (this.options.missing_key_callback) { |
|
|
|
if (this.options.missing_key_callback) { |
|
|
|
this.options.missing_key_callback(key); |
|
|
|
this.options.missing_key_callback(key, domain); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
res = [ singular_key, plural_key ]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// collect untranslated strings
|
|
|
|
|
|
|
|
if (this.options.debug===true) { |
|
|
|
|
|
|
|
console.log(res[ getPluralFormFunc(pluralForms)( val ) ]); |
|
|
|
} |
|
|
|
} |
|
|
|
res = [ null, singular_key, plural_key ]; |
|
|
|
return res[ getPluralFormFunc()( val ) ]; |
|
|
|
return res[ getPluralFormFunc(pluralForms)( val ) + 1 ]; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
res = val_list[ val_idx ]; |
|
|
|
res = val_list[ val_idx ]; |
|
|
|
|
|
|
|
|
|
|
|
// This includes empty strings on purpose
|
|
|
|
// This includes empty strings on purpose
|
|
|
|
if ( ! res ) { |
|
|
|
if ( ! res ) { |
|
|
|
res = [ null, singular_key, plural_key ]; |
|
|
|
res = [ singular_key, plural_key ]; |
|
|
|
return res[ getPluralFormFunc(pluralForms)( val ) + 1 ]; |
|
|
|
return res[ getPluralFormFunc()( val ) ]; |
|
|
|
} |
|
|
|
} |
|
|
|
return res; |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
|