Skip to content

Commit 0a52236

Browse files
grahamscoderifous
authored andcommitted
Fixed localization for input elements using plain objects for translation value.
Before this change, if you tried to using a plain object as the localization value for input elements (e.g. trying to localize the title), then the value would be set to "[Object object]". After this change, you can set the translation value to an object with +title+ and +value+ properties that will be used to set the title and placeholder of the input element.
1 parent e24f02d commit 0a52236

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

build/jquery.localize.js

+4-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/jquery.localize.coffee

+3-2
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,11 @@ $.localize = (pkg, options = {}) ->
8282
localizeForSpecialKeys(elem, value) if $.isPlainObject(value)
8383

8484
localizeInputElement = (elem, key, value) ->
85+
val = if $.isPlainObject(value) then value.value else value
8586
if elem.is("[placeholder]")
86-
elem.attr("placeholder", value)
87+
elem.attr("placeholder", val)
8788
else
88-
elem.val(value)
89+
elem.val(val)
8990

9091
localizeForSpecialKeys = (elem, value) ->
9192
setAttrFromValueForKey(elem, "title", value)

test/lang/test-ja.json

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
"test": {
33
"nested": "nested success",
44
"input": "input success",
5+
"input_as_obj": {
6+
"value": "input_as_obj value success",
7+
"title": "input_as_obj title success"
8+
},
59
"optgroup": "optgroup success",
610
"option": "option success",
711
"ruby_image": {

test/localize_test.coffee

+15
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ test "input tag placeholder substitution", ->
5252
t.localize("test", @testOpts)
5353
equals t.attr("placeholder"), "input success"
5454

55+
test "titled input tag value substitution", ->
56+
t = localizableTagWithRel("input", "test.input_as_obj", val: "input_as_obj fail")
57+
t.localize("test", @testOpts)
58+
equals t.val(), "input_as_obj value success"
59+
60+
test "titled input tag title substitution", ->
61+
t = localizableTagWithRel("input", "test.input_as_obj", val: "input_as_obj fail")
62+
t.localize("test", @testOpts)
63+
equals t.attr("title"), "input_as_obj title success"
64+
65+
test "titled input tag placeholder substitution", ->
66+
t = localizableTagWithRel("input", "test.input_as_obj", placeholder: "placeholder fail")
67+
t.localize("test", @testOpts)
68+
equals t.attr("placeholder"), "input_as_obj value success"
69+
5570
test "image tag src, alt, and title substitution", ->
5671
t = localizableTagWithRel("img", "test.ruby_image", src: "ruby_square.gif", alt: "a square ruby", title: "A Square Ruby")
5772
t.localize("test", @testOpts)

0 commit comments

Comments
 (0)