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,a=sledru
authorMark Banner <standard8@mozilla.com>
Tue, 27 Jan 2015 21:14:58 +0000
changeset 243088 fac8edb83df7
parent 243082 0043397aaa19
child 243089 e535371efd2c
push id4401
push usermbanner@mozilla.com
push date2015-01-29 09:24 +0000
treeherdermozilla-beta@fac8edb83df7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, sledru
bugs1118393
milestone36.0
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,a=sledru
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
@@ -66,16 +66,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");
+  });
+});