From 287dc947e7c666cfc2730b2a3493760f69b9e9d0 Mon Sep 17 00:00:00 2001 From: Adam McCormick Date: Fri, 20 Sep 2013 09:55:07 -0600 Subject: [PATCH 1/2] Minor change to not localize if the language pack does not have the key specified --- build/jquery.localize.js | 4 ++-- src/jquery.localize.coffee | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/build/jquery.localize.js b/build/jquery.localize.js index 2386b41..368a999 100644 --- a/build/jquery.localize.js +++ b/build/jquery.localize.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.3.3 +// Generated by CoffeeScript 1.6.3 (function() { var $, normaliseLang; @@ -99,7 +99,7 @@ localizeImageElement(elem, key, value); } else if (elem.is('optgroup')) { localizeOptgroupElement(elem, key, value); - } else if (!$.isPlainObject(value)) { + } else if ((value !== null) && !$.isPlainObject(value)) { elem.html(value); } if ($.isPlainObject(value)) { diff --git a/src/jquery.localize.coffee b/src/jquery.localize.coffee index a2e843a..0ab6f81 100644 --- a/src/jquery.localize.coffee +++ b/src/jquery.localize.coffee @@ -78,7 +78,8 @@ $.localize = (pkg, options = {}) -> if elem.is('input') then localizeInputElement(elem, key, value) else if elem.is('img') then localizeImageElement(elem, key, value) else if elem.is('optgroup') then localizeOptgroupElement(elem, key, value) - else unless $.isPlainObject(value) then elem.html(value) + else if (value != null) and not $.isPlainObject(value) \ + then elem.html(value) localizeForSpecialKeys(elem, value) if $.isPlainObject(value) localizeInputElement = (elem, key, value) -> From 1643e6339a1b656d7a0dbc2f86f282b6540540b2 Mon Sep 17 00:00:00 2001 From: Adam McCormick Date: Wed, 25 Sep 2013 09:23:00 -0600 Subject: [PATCH 2/2] Add tests proving that spans are now handled correctly --- test/localize_test.coffee | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/test/localize_test.coffee b/test/localize_test.coffee index d0a723f..a2497d1 100644 --- a/test/localize_test.coffee +++ b/test/localize_test.coffee @@ -42,6 +42,37 @@ test "basic tag text substitution for special title key", -> equals t.text(), "with_title text success" equals t.attr("title"), "with_title title success" +test "span tag text substitution", -> + t = localizableTagWithRel("span", "basic", text: "basic fail") + t.localize("test", @testOpts) + equals t.text(), "basic success" + +test "span tag text substitution using data-localize instead of rel", -> + t = localizableTagWithDataLocalize("span", "basic", text: "basic fail") + t.localize("test", @testOpts) + equals t.text(), "basic success" + +test "span tag text substitution with nested key", -> + t = localizableTagWithRel("span", "test.nested", text: "nested fail") + t.localize("test", @testOpts) + equals t.text(), "nested success" + +test "span tag text substitution for special title key", -> + t = localizableTagWithDataLocalize("span", "with_title", text: "with_title element fail", title: "with_title title fail") + t.localize("test", @testOpts) + equals t.text(), "with_title text success" + equals t.attr("title"), "with_title title success" + +test "span tag text substitution with bad key does nothing", -> + t = localizableTagWithRel("span", "span.doesnt_exist", text: "span success") + t.localize("test", @testOpts) + equals t.text(), "span success" + +test "span tag text substitution using data-localize instead of rel with bad key does nothing", -> + t = localizableTagWithDataLocalize("span", "span.doesnt_exist", text: "span success") + t.localize("test", @testOpts) + equals t.text(), "span success" + test "input tag value substitution", -> t = localizableTagWithRel("input", "test.input", val: "input fail") t.localize("test", @testOpts) @@ -104,7 +135,7 @@ test "option tag text substitution", -> module "Options" test "pathPrefix loads lang files from custom path", -> - opts = language: "fo", pathPrefix: "/test/lang/custom" + opts = language: "fo", pathPrefix: "../test/lang/custom" t = localizableTagWithRel("p", "path_prefix", text: "pathPrefix fail") t.localize("test", opts) equals t.text(), "pathPrefix success"