Bug 1118393 - Cannot use {{num}} in rooms_list_current_conversations - Don't remove the num argument for plural forms, as its a valid possible value. r=jaws
authorMark Banner <standard8@mozilla.com>
Tue, 27 Jan 2015 21:14:58 +0000
changeset 239347 31f70be9d69ab902a9cc3a5b6ddc695a1711fa74
parent 239346 a5099b806777051759c04f39ec433b970f7b4298
child 239348 1cb7264b9553bd7220a238a1c665f6750aa936fc
push id497
push usermleibovic@mozilla.com
push dateWed, 28 Jan 2015 16:43:37 +0000
reviewersjaws
bugs1118393
milestone38.0a1
Bug 1118393 - Cannot use {{num}} in rooms_list_current_conversations - Don't remove the num argument for plural forms, as its a valid possible value. r=jaws
browser/components/loop/content/libs/l10n.js
browser/components/loop/test/desktop-local/index.html
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
@@ -35,17 +35,16 @@
       return name in args ? args[name] : '{{' + name + '}}';
     });
   }
 
   // translate a string
   function translateString(key, args, fallback) {
     if (args && args.num) {
       var num = args && args.num;
-      delete 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/index.html
+++ b/browser/components/loop/test/desktop-local/index.html
@@ -68,16 +68,17 @@
   <!-- Test scripts -->
   <script src="conversationAppStore_test.js"></script>
   <script src="client_test.js"></script>
   <script src="conversation_test.js"></script>
   <script src="panel_test.js"></script>
   <script src="roomViews_test.js"></script>
   <script src="conversationViews_test.js"></script>
   <script src="contacts_test.js"></script>
+  <script src="l10n_test.js"></script>
   <script>
     // Stop the default init functions running to avoid conflicts in tests
     document.removeEventListener('DOMContentLoaded', loop.panel.init);
     document.removeEventListener('DOMContentLoaded', loop.conversation.init);
 
     describe("Uncaught Error Check", function() {
       it("should load the tests without errors", function() {
         expect(uncaughtError && uncaughtError.message).to.be.undefined;
new file mode 100644
--- /dev/null
+++ b/browser/components/loop/test/desktop-local/l10n_test.js
@@ -0,0 +1,37 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var expect = chai.expect;
+
+describe("document.mozL10n", function() {
+  "use strict";
+
+  var fakeMozLoop;
+
+  beforeEach(function() {
+    fakeMozLoop = {
+      locale: "en-US",
+      getStrings: function(key) {
+        if (key === "plural") {
+          return '{"textContent":"{{num}} plural form;{{num}} plural forms"}';
+        }
+
+        return '{"textContent":"' + key + '"}';
+      },
+      getPluralForm: function(num, string) {
+        return string.split(";")[num === 0 ? 0 : 1];
+      }
+    };
+
+    document.mozL10n.initialize(fakeMozLoop);
+  });
+
+  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");
+  });
+});