Bug 1009795 - Part 2: Revert to the old gDecimalSymbol hack if the Internationalization API is not available; r=mak
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 31 Aug 2015 23:20:05 -0400
changeset 260742 fcf97e4f647941218d2e1df9408307424c859690
parent 260741 b52ff9f176fda666964ec21ec4c52acef73f8d1b
child 260743 b82c3dd381db73184b1b6427429dcbbce65e3ab3
push id64573
push usereakhgari@mozilla.com
push dateThu, 03 Sep 2015 22:55:47 +0000
treeherdermozilla-inbound@fcf97e4f6479 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1009795, 1200494
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
--- a/toolkit/mozapps/downloads/DownloadUtils.jsm
+++ b/toolkit/mozapps/downloads/DownloadUtils.jsm
@@ -41,16 +41,21 @@ const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 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
   let locale = Intl.NumberFormat().resolvedOptions().locale +
                "-u-nu-latn";
   let key = locale + "_" + fractionDigits;
   if (!localeNumberFormatCache.has(key)) {
     localeNumberFormatCache.set(key,
@@ -473,18 +478,23 @@ this.DownloadUtils = {
     // 0 -> 0; 1.2 -> 1.2; 12.3 -> 12.3; 123.4 -> 123; 234.5 -> 235
     // added in bug 462064: (unitIndex != 0) makes sure that no decimal digit for bytes appears when aBytes < 100
     let fractionDigits = (aBytes > 0) && (aBytes < 100) && (unitIndex != 0) ? 1 : 0;
 
     // Don't try to format Infinity values using NumberFormat.
     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])];
   },
 
   /**
    * Converts a number of seconds to the two largest units. Time values are
    * whole numbers, and units have the correct plural/singular form.