Skip to content

Commit

Permalink
Added fileExtension option for language resource files.
Browse files Browse the repository at this point in the history
Closes #16
  • Loading branch information
coderifous committed Mar 14, 2012
1 parent 21a7ffe commit 3d837ed
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
9 changes: 5 additions & 4 deletions build/jquery.localize.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions src/jquery.localize.coffee
Expand Up @@ -20,23 +20,24 @@ $.defaultLanguage = normaliseLang(navigator.language || navigator.userLanguage)
$.localize = (pkg, options = {}) ->
wrappedSet = this
intermediateLangData = {}
fileExtension = options.fileExtension || "json"

loadLanguage = (pkg, lang, level = 1) ->
switch level
when 1
intermediateLangData = {}
if options.loadBase
file = pkg + '.json'
file = pkg + ".#{fileExtension}"
jsonCall(file, pkg, lang, level)
else
loadLanguage(pkg, lang, 2)
when 2
if lang.length >= 2
file = "#{pkg}-#{lang.substring(0, 2)}.json"
file = "#{pkg}-#{lang.substring(0, 2)}.#{fileExtension}"
jsonCall(file, pkg, lang, level)
when 3
if lang.length >= 5
file = "#{pkg}-#{lang.substring(0, 5)}.json"
file = "#{pkg}-#{lang.substring(0, 5)}.#{fileExtension}"
jsonCall(file, pkg, lang, level)

jsonCall = (file, pkg, lang, level) ->
Expand Down
4 changes: 4 additions & 0 deletions test/lang/test-ja.foo
@@ -0,0 +1,4 @@
{
"basic": "basic success foo"
}

5 changes: 5 additions & 0 deletions test/localize_test.coffee
Expand Up @@ -45,6 +45,11 @@ test "chained call", ->
t.localize("test", @testOpts).localize("test", @testOpts)
equals t.text(), "basic success"

test "alternative file extension", ->
t = localizableTag("p", "basic", text: "basic fail")
t.localize("test", $.extend({ fileExtension: "foo" }, @testOpts))
equals t.text(), "basic success foo"

moreSetup ->
@t = $('
<select>
Expand Down

0 comments on commit 3d837ed

Please sign in to comment.