Skip to content

Commit 1b602f0

Browse files
committed
Added support for localizing input placeholders. [Closes #4]
1 parent 740b51d commit 1b602f0

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

build/jquery.localize.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/jquery.localize.coffee

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ $.localize = (pkg, options = {}) ->
6565
key = elem.attr("rel").match(/localize\[(.*?)\]/)[1]
6666
value = valueForKey(key, data)
6767
if elem.is('input')
68-
elem.val(value)
68+
if elem.is("[placeholder]")
69+
elem.attr("placeholder", value)
70+
else
71+
elem.val(value)
6972
else if elem.is('optgroup')
7073
elem.attr("label", value)
7174
else if elem.is('img')

test/localize_test.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ test "input tag value substitution", ->
2929
t.localize("test", @testOpts)
3030
equals t.val(), "input success"
3131

32+
test "input tag placeholder substitution", ->
33+
t = localizableTag("input", "test.input", placeholder: "placeholder fail")
34+
t.localize("test", @testOpts)
35+
equals t.attr("placeholder"), "input success"
36+
3237
test "image tag src and alt substitution", ->
3338
t = localizableTag("img", "test.ruby_image", src: "ruby_square.gif", alt: "a square ruby")
3439
t.localize("test", @testOpts)

0 commit comments

Comments
 (0)