app/assets/javascripts/i18n.js in i18n-js-3.0.0.rc3 vs app/assets/javascripts/i18n.js in i18n-js-3.0.0.rc4

- old
+ new

@@ -114,12 +114,11 @@ } return list; }; - // - // + // Hold pluralization rules. I18n.pluralization = {}; // Return the pluralizer for a specific locale. // If no specify locale is found, then I18n's default will be used. I18n.pluralization.get = function(locale) { @@ -174,16 +173,16 @@ } while (scopes.length) { translations = translations[scopes.shift()]; - if (!translations) { + if (translations === undefined || translations === null) { break; } } - if (translations) { + if (translations !== undefined && translations !== null) { return translations; } } if (this.isSet(options.defaultValue)) { @@ -228,11 +227,11 @@ // Translate the given scope with the provided options. I18n.translate = function(scope, options) { options = this.prepareOptions(options); var translation = this.lookup(scope, options); - if (!translation) { + if (translation === undefined || translation === null) { return this.missingTranslation(scope); } if (typeof(translation) === "string") { translation = this.interpolate(translation, options); @@ -330,13 +329,13 @@ // // You can also override these options by providing the `options` argument. // I18n.toNumber = function(number, options) { options = this.prepareOptions( - options, - this.lookup("number.format"), - {precision: 3, separator: ".", delimiter: ",", strip_insignificant_zeros: false} + options + , this.lookup("number.format") + , {precision: 3, separator: ".", delimiter: ",", strip_insignificant_zeros: false} ); var negative = number < 0 , string = Math.abs(number).toFixed(options.precision).toString() , parts = string.split(".") @@ -385,14 +384,14 @@ // // You can also override these options by providing the `options` argument. // I18n.toCurrency = function(number, options) { options = this.prepareOptions( - options, - this.lookup("number.currency.format"), - this.lookup("number.format"), - {unit: "$", precision: 2, format: "%u%n", delimiter: ",", separator: "."} + options + , this.lookup("number.currency.format") + , this.lookup("number.format") + , {unit: "$", precision: 2, format: "%u%n", delimiter: ",", separator: "."} ); number = this.toNumber(number, options); number = options.format .replace("%u", options.unit) @@ -543,13 +542,12 @@ hour12 = hour12 - 12; } else if (hour12 === 0) { hour12 = 12; } - var padding = function(n) { - var s = "0" + n.toString(); - return s.substr(s.length - 2); + var padding = function(number) { + return ("0" + number.toString()).substr(-2); }; format = format.replace("%a", options.abbr_day_names[weekDay]); format = format.replace("%A", options.day_names[weekDay]); format = format.replace("%b", options.abbr_month_names[month]); @@ -575,14 +573,13 @@ format = format.replace("%z", timezoneoffset); return format; }; - // - // - I18n.toTime = function(scope, d) { - var date = this.parseDate(d) + // Convert the given dateString into a formatted date. + I18n.toTime = function(scope, dateString) { + var date = this.parseDate(dateString) , format = this.lookup(scope) ; if (date.toString().match(/invalid/i)) { return date.toString(); @@ -593,26 +590,24 @@ } return this.strftime(date, format); }; - // - // + // Convert a number into a formatted percentage value. I18n.toPercentage = function(number, options) { options = this.prepareOptions( - options, - this.lookup("number.percentage.format"), - this.lookup("number.format"), - {precision: 3, separator: ".", delimiter: ""} + options + , this.lookup("number.percentage.format") + , this.lookup("number.format") + , {precision: 3, separator: ".", delimiter: ""} ); number = this.toNumber(number, options); return number + "%"; }; - // - // + // Convert a number into a readable size representation. I18n.toHumanSize = function(number, options) { var kb = 1024 , size = number , iterations = 0 , unit @@ -631,12 +626,12 @@ unit = this.t("number.human.storage_units.units." + [null, "kb", "mb", "gb", "tb"][iterations]); precision = (size - Math.floor(size) === 0) ? 0 : 1; } options = this.prepareOptions( - options, - {precision: precision, format: "%n%u", delimiter: ""} + options + , {precision: precision, format: "%n%u", delimiter: ""} ); number = this.toNumber(size, options); number = options.format .replace("%u", unit) @@ -648,6 +643,6 @@ // Set aliases, so we can save some typing. I18n.t = I18n.translate; I18n.l = I18n.localize; I18n.p = I18n.pluralize; -})(typeof(exports) === "undefined" ? this["I18n"] = {} : exports); +})(typeof(exports) === "undefined" ? {} : exports);