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/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");
+ });
+});