Browse Source

Update jed.js to 1.1.0

pull/170/head
Evan Theurer 10 years ago
parent
commit
63324502c3
  1. 2
      package.json
  2. 2
      src/i18n/helpers/po2json
  3. 58
      static/js/libs/jed.js
  4. 16
      static/js/services/translation.js

2
package.json

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
"private": true,
"dependencies": {
"autoprefixer": ">= 3.1.0",
"po2json": ">= 0.3.0",
"po2json": ">= 0.4.1",
"jshint": ">= 2.5.5"
}
}

2
src/i18n/helpers/po2json

@ -7,7 +7,7 @@ var po2json = require('po2json'), @@ -7,7 +7,7 @@ var po2json = require('po2json'),
assert.equal(argv.length, 4, 'Usage: po2json <input_file.po> <output_file.json>');
var result = po2json.parseFileSync(argv[2], { stringify: true, format: 'jed', pretty: false }),
var result = po2json.parseFileSync(argv[2], { stringify: true, format: 'jed1.x', pretty: false }),
stream = fs.createWriteStream(argv[3], {});
stream.write(result);

58
static/js/libs/jed.js

@ -1,8 +1,7 @@ @@ -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
@ -91,7 +90,9 @@ in order to offer easy upgrades -- jsgettext.berlios.de @@ -91,7 +90,9 @@ in order to offer easy upgrades -- jsgettext.berlios.de
}
},
// 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
@ -136,7 +137,7 @@ in order to offer easy upgrades -- jsgettext.berlios.de @@ -136,7 +137,7 @@ in order to offer easy upgrades -- jsgettext.berlios.de
},
fetch : function ( sArr ) {
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; } )(
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 @@ -221,9 +222,6 @@ in order to offer easy upgrades -- jsgettext.berlios.de
// isn't explicitly passed in
domain = domain || this._textdomain;
// Default the value to the singular case
val = typeof val == 'undefined' ? 1 : val;
var fallback;
// Handle special cases
@ -257,6 +255,22 @@ in order to offer easy upgrades -- jsgettext.berlios.de @@ -257,6 +255,22 @@ in order to offer easy upgrades -- jsgettext.berlios.de
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
if ( typeof val != 'number' ) {
val = parseInt( val, 10 );
@ -266,13 +280,8 @@ in order to offer easy upgrades -- jsgettext.berlios.de @@ -266,13 +280,8 @@ in order to offer easy upgrades -- jsgettext.berlios.de
}
}
var key = context ? context + Jed.context_delimiter + singular_key : singular_key,
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;
val_idx = getPluralFormFunc(pluralForms)(val);
}
// Throw an error if a domain isn't found
if ( ! dict ) {
@ -283,20 +292,25 @@ in order to offer easy upgrades -- jsgettext.berlios.de @@ -283,20 +292,25 @@ in order to offer easy upgrades -- jsgettext.berlios.de
// If there is no match, then revert back to
// 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) {
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(pluralForms)( val ) + 1 ];
return res[ getPluralFormFunc()( val ) ];
}
res = val_list[ val_idx ];
// This includes empty strings on purpose
if ( ! res ) {
res = [ null, singular_key, plural_key ];
return res[ getPluralFormFunc(pluralForms)( val ) + 1 ];
res = [ singular_key, plural_key ];
return res[ getPluralFormFunc()( val ) ];
}
return res;
}

16
static/js/services/translation.js

@ -30,25 +30,25 @@ define(["jed", "underscore"], function(Jed, _) { @@ -30,25 +30,25 @@ define(["jed", "underscore"], function(Jed, _) {
this._ = _.bind(function() {
if (domain && context) {
return _.bind(function(singular) {
var vars = Array.prototype.slice.call(arguments, 1);
var vars = Array.prototype.slice.call(arguments, 0);
var r = i18n.translate(singular).onDomain(domain).withContext(context);
return r.fetch.apply(r, vars);
}, this);
} else if (domain) {
return _.bind(function(singular) {
var vars = Array.prototype.slice.call(arguments, 1);
var vars = Array.prototype.slice.call(arguments, 0);
var r = i18n.translate(singular).onDomain(domain);
return r.fetch.apply(r, vars);
}, this);
} else if (context) {
return _.bind(function(singular) {
var vars = Array.prototype.slice.call(arguments, 1);
var vars = Array.prototype.slice.call(arguments, 0);
var r = i18n.translate(singular).withContext(context);
return r.fetch.apply(r, vars);
}, this);
} else {
return _.bind(function(singular) {
var vars = Array.prototype.slice.call(arguments, 1);
var vars = Array.prototype.slice.call(arguments, 0);
var r = i18n.translate(singular);
return r.fetch.apply(r, vars);
}, this);
@ -59,25 +59,25 @@ define(["jed", "underscore"], function(Jed, _) { @@ -59,25 +59,25 @@ define(["jed", "underscore"], function(Jed, _) {
this._n = _.bind(function() {
if (domain && context) {
return _.bind(function(singular, plural) {
var vars = Array.prototype.slice.call(arguments, 2);
var vars = Array.prototype.slice.call(arguments, 1);
var r = i18n.translate(singular).onDomain(domain).withContext(context).ifPlural(vars[0], plural);
return r.fetch.apply(r, vars);
});
} else if (domain) {
return _.bind(function(singular, plural) {
var vars = Array.prototype.slice.call(arguments, 2);
var vars = Array.prototype.slice.call(arguments, 1);
var r = i18n.translate(singular).onDomain(domain).ifPlural(vars[0], plural);
return r.fetch.apply(r, vars);
});
} else if (context) {
return _.bind(function(singular, plural) {
var vars = Array.prototype.slice.call(arguments, 2);
var vars = Array.prototype.slice.call(arguments, 1);
var r = i18n.translate(singular).withContext(context).ifPlural(vars[0], plural);
return r.fetch.apply(r, vars);
});
} else {
return _.bind(function(singular, plural) {
var vars = Array.prototype.slice.call(arguments, 2);
var vars = Array.prototype.slice.call(arguments, 1);
var r = i18n.translate(singular).ifPlural(vars[0], plural);
return r.fetch.apply(r, vars);
})

Loading…
Cancel
Save