Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build/jquery.localize.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/jquery.localize.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
33 changes: 32 additions & 1 deletion test/localize_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down