Bug 1009795 - Part 2: Revert to the old gDecimalSymbol hack if the Internationalization API is not available; r=mak

This will be removed in bug 1200494.
This commit is contained in:
Ehsan Akhgari 2015-08-31 23:20:05 -04:00
parent 68e13b0044
commit 69a48c438f

View File

@ -46,6 +46,11 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PluralForm",
"resource://gre/modules/PluralForm.jsm");
this.__defineGetter__("gDecimalSymbol", function() {
delete this.gDecimalSymbol;
return this.gDecimalSymbol = Number(5.4).toLocaleString().match(/\D/);
});
let localeNumberFormatCache = new Map();
function getLocaleNumberFormat(fractionDigits) {
// Backward compatibility: don't use localized digits
@ -478,8 +483,13 @@ this.DownloadUtils = {
if (aBytes === Infinity) {
aBytes = "Infinity";
} else {
aBytes = getLocaleNumberFormat(fractionDigits)
.format(aBytes);
if (Intl) {
aBytes = getLocaleNumberFormat(fractionDigits)
.format(aBytes);
} else if (gDecimalSymbol != ".") {
// FIXME: Fall back to the old hack, will be fixed in bug 1200494.
aBytes = aBytes.toFixed(fractionDigits).replace(".", gDecimalSymbol);
}
}
return [aBytes, gBundle.GetStringFromName(gStr.units[unitIndex])];