app/assets/javascripts/i18n.js in i18n-js-3.0.0.rc13 vs app/assets/javascripts/i18n.js in i18n-js-3.0.0.rc14
- old
+ new
@@ -77,10 +77,24 @@
// Shift back
value = value.toString().split('e');
return +(value[0] + 'e' + (value[1] ? (+value[1] + exp) : exp));
}
+ var merge = function (dest, obj) {
+ var key, value;
+ for (key in obj) if (obj.hasOwnProperty(key)) {
+ value = obj[key];
+ if (Object.prototype.toString.call(value) === '[object String]') {
+ dest[key] = value;
+ } else {
+ if (dest[key] == null) dest[key] = {};
+ merge(dest[key], value);
+ }
+ }
+ return dest;
+ };
+
// Set default days/months translations.
var DATE = {
day_names: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
, abbr_day_names: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
, month_names: [null, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
@@ -919,22 +933,13 @@
* In order to support ES3, `Object.prototype.hasOwnProperty.call` is used
* Idea is from:
* https://stackoverflow.com/questions/8157700/object-has-no-hasownproperty-method-i-e-its-undefined-ie8
*/
I18n.extend = function ( obj1, obj2 ) {
- var extended = {};
- var prop;
- for (prop in obj1) {
- if (Object.prototype.hasOwnProperty.call(obj1, prop)) {
- extended[prop] = obj1[prop];
- }
+ if (typeof(obj1) === "undefined" && typeof(obj2) === "undefined") {
+ return {};
}
- for (prop in obj2) {
- if (Object.prototype.hasOwnProperty.call(obj2, prop)) {
- extended[prop] = obj2[prop];
- }
- }
- return extended;
+ return merge(obj1, obj2);
};
// Set aliases, so we can save some typing.
I18n.t = I18n.translate;
I18n.l = I18n.localize;