Bug 1172768 - Loop's desktop plural form handling doesn't handle zeros very well. r=mikedeboer
authorMark Banner <standard8@mozilla.com>
Wed, 10 Jun 2015 14:12:42 +0100
changeset 248132 04d1294656a1ed703e837991d1b487b563f85405
parent 248131 2ba82990c44b6a733a097e2c2585c972d0f44465
child 248133 b971fbbbe37e14d786e036758a1302eacadce226
push id60888
push userkwierso@gmail.com
push dateThu, 11 Jun 2015 01:38:38 +0000
treeherdermozilla-inbound@39e638ed06bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1172768
milestone41.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 1172768 - Loop's desktop plural form handling doesn't handle zeros very well. r=mikedeboer
browser/components/loop/content/libs/l10n.js
browser/components/loop/test/desktop-local/l10n_test.js
--- a/browser/components/loop/content/libs/l10n.js
+++ b/browser/components/loop/content/libs/l10n.js
@@ -33,18 +33,19 @@
 
     return text.replace(/\{\{\s*(\w+)\s*\}\}/g, function(all, name) {
       return name in args ? args[name] : '{{' + name + '}}';
     });
   }
 
   // translate a string
   function translateString(key, args, fallback) {
-    if (args && args.num) {
-      var num = args && args.num;
+    var num;
+    if (args && ("num" in args)) {
+      num = args.num;
     }
     var data = getL10nData(key, num);
     if (!data && fallback)
       data = {textContent: fallback};
     if (!data)
       return '{{' + key + '}}';
     return substArguments(data.textContent, args);
   }
--- a/browser/components/loop/test/desktop-local/l10n_test.js
+++ b/browser/components/loop/test/desktop-local/l10n_test.js
@@ -29,9 +29,13 @@ describe("document.mozL10n", function() 
 
   it("should get a simple string", function() {
     expect(document.mozL10n.get("test")).eql("test");
   });
 
   it("should get a plural form", function() {
     expect(document.mozL10n.get("plural", {num: 10})).eql("10 plural forms");
   });
+
+  it("should correctly get a plural form for num = 0", function() {
+    expect(document.mozL10n.get("plural", {num: 0})).eql("0 plural form");
+  });
 });