From 69a48c438f262e82f66f0921a460bc11ca59fd86 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Mon, 31 Aug 2015 23:20:05 -0400 Subject: [PATCH] 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. --- toolkit/mozapps/downloads/DownloadUtils.jsm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/toolkit/mozapps/downloads/DownloadUtils.jsm b/toolkit/mozapps/downloads/DownloadUtils.jsm index 5cefcf566412..26f89f9d0d55 100644 --- a/toolkit/mozapps/downloads/DownloadUtils.jsm +++ b/toolkit/mozapps/downloads/DownloadUtils.jsm @@ -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])];