diff --git a/toolkit/locales/en-US/chrome/mozapps/downloads/downloads.properties b/toolkit/locales/en-US/chrome/mozapps/downloads/downloads.properties index 2bd5fc9efbe5..4abc9f9017ca 100644 --- a/toolkit/locales/en-US/chrome/mozapps/downloads/downloads.properties +++ b/toolkit/locales/en-US/chrome/mozapps/downloads/downloads.properties @@ -44,11 +44,20 @@ dontLeavePrivateBrowsingButton=Stay in Private Browsing Mode downloadsCompleteTitle=Downloads Complete downloadsCompleteMsg=All files have finished downloading. +# LOCALIZATION NOTE (infiniteRate): +# If download speed is a JavaScript Infinity value, this phrase is used +infiniteRate=Really fast + # LOCALIZATION NOTE (statusFormat3): — is the "em dash" (long dash) # %1$S transfer progress; %2$S rate number; %3$S rate unit; %4$S time left # example: 4 minutes left — 1.1 of 11.1 GB (2.2 MB/sec) statusFormat3=%4$S — %1$S (%2$S %3$S/sec) +# LOCALIZATION NOTE (statusFormatInfiniteRate): — is the "em dash" (long dash) +# %1$S transfer progress; %2$S substitute phrase for Infinity speed; %3$S time left +# example: 4 minutes left — 1.1 of 11.1 GB (Really fast) +statusFormatInfiniteRate=%3$S — %1$S (%2$S) + # LOCALIZATION NOTE (statusFormatNoRate): — is the "em dash" (long dash) # %1$S transfer progress; %2$S time left # example: 4 minutes left — 1.1 of 11.1 GB diff --git a/toolkit/mozapps/downloads/DownloadUtils.jsm b/toolkit/mozapps/downloads/DownloadUtils.jsm index 2748d3856293..8f470c3e474c 100644 --- a/toolkit/mozapps/downloads/DownloadUtils.jsm +++ b/toolkit/mozapps/downloads/DownloadUtils.jsm @@ -55,6 +55,7 @@ const kDownloadProperties = let gStr = { statusFormat: "statusFormat3", + statusFormatInfiniteRate: "statusFormatInfiniteRate", statusFormatNoRate: "statusFormatNoRate", transferSameUnits: "transferSameUnits2", transferDiffUnits: "transferDiffUnits2", @@ -71,6 +72,7 @@ let gStr = { units: ["bytes", "kilobyte", "megabyte", "gigabyte"], // Update timeSize in convertTimeUnits if changing the length of this array timeUnits: ["seconds", "minutes", "hours", "days"], + infiniteRate: "infiniteRate", }; // This lazily initializes the string bundle upon first use. @@ -108,9 +110,19 @@ this.DownloadUtils = { = this._deriveTransferRate(aCurrBytes, aMaxBytes, aSpeed, aLastSec); let [rate, unit] = DownloadUtils.convertByteUnits(normalizedSpeed); - let params = [transfer, rate, unit, timeLeft]; - let status = gBundle.formatStringFromName(gStr.statusFormat, params, - params.length); + + let status; + if (rate === "Infinity") { + // Infinity download speed doesn't make sense. Show a localized phrase instead. + let params = [transfer, gBundle.GetStringFromName(gStr.infiniteRate), timeLeft]; + status = gBundle.formatStringFromName(gStr.statusFormatInfiniteRate, params, + params.length); + } + else { + let params = [transfer, rate, unit, timeLeft]; + status = gBundle.formatStringFromName(gStr.statusFormat, params, + params.length); + } return [status, newLast]; }, diff --git a/toolkit/mozapps/downloads/tests/unit/test_DownloadUtils.js b/toolkit/mozapps/downloads/tests/unit/test_DownloadUtils.js index 98b7f40ac2be..62150cb7cc5c 100644 --- a/toolkit/mozapps/downloads/tests/unit/test_DownloadUtils.js +++ b/toolkit/mozapps/downloads/tests/unit/test_DownloadUtils.js @@ -26,7 +26,7 @@ function testTransferTotal(aCurrBytes, aMaxBytes, aTransfer) // Get the em-dash character because typing it directly here doesn't work :( let gDash = DownloadUtils.getDownloadStatus(0)[0].match(/remaining (.) 0 bytes/)[1]; -let gVals = [0, 100, 2345, 55555, 982341, 23194134, 1482, 58, 9921949201, 13498132]; +let gVals = [0, 100, 2345, 55555, 982341, 23194134, 1482, 58, 9921949201, 13498132, Infinity]; function testStatus(aFunc, aCurr, aMore, aRate, aTest) { @@ -167,6 +167,9 @@ function run_test() testStatus(statusFunc, 6, 6, 0, ["Unknown time remaining -- 1.4 of 2.9 KB (0 bytes/sec)", Infinity]); testStatus(statusFunc, 8, 5, 0, ["Unknown time remaining -- 9.2 of 9.3 GB (0 bytes/sec)", Infinity]); + // With rate equal to Infinity + testStatus(statusFunc, 0, 0, 10, ["Unknown time remaining -- 0 of 0 bytes (Really fast)", Infinity]); + testStatus(statusFunc, 1, 2, 10, ["A few seconds remaining -- 100 bytes of 2.4 KB (Really fast)", 0]); // Now test without rates, via getDownloadStatusNoRate. statusFunc = DownloadUtils.getDownloadStatusNoRate.bind(DownloadUtils);