Skip to content

Commit 1b97554

Browse files
committed
Added support for IMG src and alt attributes. [Closes #5]
1 parent c7f951f commit 1b97554

File tree

6 files changed

+23
-1
lines changed

6 files changed

+23
-1
lines changed

build/jquery.localize.js

Lines changed: 9 additions & 0 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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ $.localize = (pkg, options = {}) ->
6868
elem.val(value)
6969
else if elem.is('optgroup')
7070
elem.attr("label", value)
71+
else if elem.is('img')
72+
value = valueForKey("#{key}.alt", data)
73+
elem.attr("alt", value) if value?
74+
value = valueForKey("#{key}.src", data)
75+
elem.attr("src", value) if value?
7176
else
7277
elem.html(value)
7378

test/basic_usage.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ <h1>Test localization...</h1>
2121
<option rel="localize[test.option]" value="1">Fail</option>
2222
</optgroup>
2323
</select>
24+
<p>
25+
<img src="ruby_square.gif" alt="a square ruby" rel="localize[test.ruby_image]"/>
26+
Ruby image should be round.
27+
</p>
2428
<p rel="localize[message]">It failed :(</p>
2529
<script type="text/javascript" charset="utf-8">
2630
$(function(){

test/lang/test-ja.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
"iteration": "Iterator foo = foo.iterator()",
66
"input": "success",
77
"optgroup": "success",
8-
"option": "success"
8+
"option": "success",
9+
"ruby_image": {
10+
"src": "ruby_round.gif",
11+
"alt": "a round ruby"
12+
}
913
},
1014
"message": "It worked!"
1115
}

test/ruby_round.gif

2.67 KB
Loading

test/ruby_square.gif

2.16 KB
Loading

0 commit comments

Comments
 (0)