Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions dist/jquery.localize.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,11 @@ http://keith-wood.name/localisation.html
}
break;
case 2:
if (lang.length >= 2) {
file = "" + pkg + "-" + (lang.substring(0, 2)) + "." + fileExtension;
return jsonCall(file, pkg, lang, level);
}
break;
file = "" + pkg + "-" + (lang.split('-')[0]) + "." + fileExtension;
return jsonCall(file, pkg, lang, level);
case 3:
if (lang.length >= 5) {
file = "" + pkg + "-" + (lang.substring(0, 5)) + "." + fileExtension;
return jsonCall(file, pkg, lang, level);
}
file = "" + pkg + "-" + (lang.split('-').slice(0, 2).join('-')) + "." + fileExtension;
return jsonCall(file, pkg, lang, level);
}
};
jsonCall = function(file, pkg, lang, level) {
Expand Down
6 changes: 3 additions & 3 deletions dist/jquery.localize.min.js

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

10 changes: 4 additions & 6 deletions src/jquery.localize.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ do ($ = jQuery) ->
else
loadLanguage(pkg, lang, 2)
when 2
if lang.length >= 2
file = "#{pkg}-#{lang.substring(0, 2)}.#{fileExtension}"
jsonCall(file, pkg, lang, level)
file = "#{pkg}-#{lang.split('-')[0]}.#{fileExtension}"
jsonCall(file, pkg, lang, level)
when 3
if lang.length >= 5
file = "#{pkg}-#{lang.substring(0, 5)}.#{fileExtension}"
jsonCall(file, pkg, lang, level)
file = "#{pkg}-#{lang.split('-').slice(0,2).join('-')}.#{fileExtension}"
jsonCall(file, pkg, lang, level)

jsonCall = (file, pkg, lang, level) ->
file = "#{options.pathPrefix}/#{file}" if options.pathPrefix?
Expand Down
3 changes: 3 additions & 0 deletions test/lang/test-ast.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"basic": "basic success"
}
7 changes: 7 additions & 0 deletions test/localize_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ do ($ = jQuery) ->
t.localize("test", opts)
equal t.text(), "country code success"

# Ref: https://github.com/coderifous/jquery-localize/issues/50
test "three-letter language code", ->
opts = language: "ast", pathPrefix: "lang"
t = localizableTagWithRel("p", "basic", text: "basic fail")
t.localize("test", opts)
equal t.text(), "basic success"

module "Language optimization"

test "skipping language using string match", ->
Expand Down
12 changes: 12 additions & 0 deletions test/localize_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,18 @@
t.localize("test", opts);
return equal(t.text(), "country code success");
});
test("three-letter language code", function() {
var opts, t;
opts = {
language: "ast",
pathPrefix: "lang"
};
t = localizableTagWithRel("p", "basic", {
text: "basic fail"
});
t.localize("test", opts);
return equal(t.text(), "basic success");
});
module("Language optimization");
test("skipping language using string match", function() {
var opts, t;
Expand Down