Skip to content

Commit 2ca4452

Browse files
committed
Fixed blanking of values for missing lang keys.
Closes #37.
1 parent 6bdbf5f commit 2ca4452

6 files changed

+23
-4
lines changed

dist/jquery.localize.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ http://keith-wood.name/localisation.html
9898
key = elem.data("localize");
9999
key || (key = elem.attr("rel").match(/localize\[(.*?)\]/)[1]);
100100
value = valueForKey(key, data);
101-
return localizeElement(elem, key, value);
101+
if (value != null) {
102+
return localizeElement(elem, key, value);
103+
}
102104
});
103105
};
104106
localizeElement = function(elem, key, value) {

dist/jquery.localize.min.js

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

src/jquery.localize.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ do ($ = jQuery) ->
7878
key = elem.data("localize")
7979
key ||= elem.attr("rel").match(/localize\[(.*?)\]/)[1]
8080
value = valueForKey(key, data)
81-
localizeElement(elem, key, value)
81+
localizeElement(elem, key, value) if value?
8282

8383
localizeElement = (elem, key, value) ->
8484
if elem.is('input') then localizeInputElement(elem, key, value)

test/lang/test2-ja.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}

test/localize_test.coffee

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ do ($ = jQuery) ->
4949
t.localize("test", @testOpts)
5050
equal t.val(), "input success"
5151

52+
test "input tag value after second localization without key", ->
53+
t = localizableTagWithRel("input", "test.input", val: "input fail")
54+
t.localize("test", @testOpts)
55+
t.localize("test2", @testOpts)
56+
equal t.val(), "input success"
57+
5258
test "input tag placeholder substitution", ->
5359
t = localizableTagWithRel("input", "test.input", placeholder: "placeholder fail")
5460
t.localize("test", @testOpts)

test/localize_test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@
7575
t.localize("test", this.testOpts);
7676
return equal(t.val(), "input success");
7777
});
78+
test("input tag value after second localization without key", function() {
79+
var t;
80+
t = localizableTagWithRel("input", "test.input", {
81+
val: "input fail"
82+
});
83+
t.localize("test", this.testOpts);
84+
t.localize("test2", this.testOpts);
85+
return equal(t.val(), "input success");
86+
});
7887
test("input tag placeholder substitution", function() {
7988
var t;
8089
t = localizableTagWithRel("input", "test.input", {

0 commit comments

Comments
 (0)