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) -> 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"