Skip to content

Commit 3d837ed

Browse files
committed
Added fileExtension option for language resource files.
Closes #16
1 parent 21a7ffe commit 3d837ed

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

build/jquery.localize.js

Lines changed: 5 additions & 4 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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,24 @@ $.defaultLanguage = normaliseLang(navigator.language || navigator.userLanguage)
2020
$.localize = (pkg, options = {}) ->
2121
wrappedSet = this
2222
intermediateLangData = {}
23+
fileExtension = options.fileExtension || "json"
2324

2425
loadLanguage = (pkg, lang, level = 1) ->
2526
switch level
2627
when 1
2728
intermediateLangData = {}
2829
if options.loadBase
29-
file = pkg + '.json'
30+
file = pkg + ".#{fileExtension}"
3031
jsonCall(file, pkg, lang, level)
3132
else
3233
loadLanguage(pkg, lang, 2)
3334
when 2
3435
if lang.length >= 2
35-
file = "#{pkg}-#{lang.substring(0, 2)}.json"
36+
file = "#{pkg}-#{lang.substring(0, 2)}.#{fileExtension}"
3637
jsonCall(file, pkg, lang, level)
3738
when 3
3839
if lang.length >= 5
39-
file = "#{pkg}-#{lang.substring(0, 5)}.json"
40+
file = "#{pkg}-#{lang.substring(0, 5)}.#{fileExtension}"
4041
jsonCall(file, pkg, lang, level)
4142

4243
jsonCall = (file, pkg, lang, level) ->

test/lang/test-ja.foo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"basic": "basic success foo"
3+
}
4+

test/localize_test.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ test "chained call", ->
4545
t.localize("test", @testOpts).localize("test", @testOpts)
4646
equals t.text(), "basic success"
4747

48+
test "alternative file extension", ->
49+
t = localizableTag("p", "basic", text: "basic fail")
50+
t.localize("test", $.extend({ fileExtension: "foo" }, @testOpts))
51+
equals t.text(), "basic success foo"
52+
4853
moreSetup ->
4954
@t = $('
5055
<select>

0 commit comments

Comments
 (0)