Skip to content

Commit e86aee7

Browse files
authored
Merge pull request #87 from oSoMoN/fix-issue-50
Fix issue #50
2 parents dc8853a + d41a5c5 commit e86aee7

File tree

6 files changed

+33
-18
lines changed

6 files changed

+33
-18
lines changed

dist/jquery.localize.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,11 @@ http://keith-wood.name/localisation.html
4141
}
4242
break;
4343
case 2:
44-
if (lang.length >= 2) {
45-
file = "" + pkg + "-" + (lang.substring(0, 2)) + "." + fileExtension;
46-
return jsonCall(file, pkg, lang, level);
47-
}
48-
break;
44+
file = "" + pkg + "-" + (lang.split('-')[0]) + "." + fileExtension;
45+
return jsonCall(file, pkg, lang, level);
4946
case 3:
50-
if (lang.length >= 5) {
51-
file = "" + pkg + "-" + (lang.substring(0, 5)) + "." + fileExtension;
52-
return jsonCall(file, pkg, lang, level);
53-
}
47+
file = "" + pkg + "-" + (lang.split('-').slice(0, 2).join('-')) + "." + fileExtension;
48+
return jsonCall(file, pkg, lang, level);
5449
}
5550
};
5651
jsonCall = function(file, pkg, lang, level) {

dist/jquery.localize.min.js

Lines changed: 3 additions & 3 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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@ do ($ = jQuery) ->
3434
else
3535
loadLanguage(pkg, lang, 2)
3636
when 2
37-
if lang.length >= 2
38-
file = "#{pkg}-#{lang.substring(0, 2)}.#{fileExtension}"
39-
jsonCall(file, pkg, lang, level)
37+
file = "#{pkg}-#{lang.split('-')[0]}.#{fileExtension}"
38+
jsonCall(file, pkg, lang, level)
4039
when 3
41-
if lang.length >= 5
42-
file = "#{pkg}-#{lang.substring(0, 5)}.#{fileExtension}"
43-
jsonCall(file, pkg, lang, level)
40+
file = "#{pkg}-#{lang.split('-').slice(0,2).join('-')}.#{fileExtension}"
41+
jsonCall(file, pkg, lang, level)
4442

4543
jsonCall = (file, pkg, lang, level) ->
4644
file = "#{options.pathPrefix}/#{file}" if options.pathPrefix?

test/lang/test-ast.json

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

test/localize_test.coffee

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ do ($ = jQuery) ->
149149
t.localize("test", opts)
150150
equal t.text(), "country code success"
151151

152+
# Ref: https://github.com/coderifous/jquery-localize/issues/50
153+
test "three-letter language code", ->
154+
opts = language: "ast", pathPrefix: "lang"
155+
t = localizableTagWithRel("p", "basic", text: "basic fail")
156+
t.localize("test", opts)
157+
equal t.text(), "basic success"
158+
152159
module "Language optimization"
153160

154161
test "skipping language using string match", ->

test/localize_test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,18 @@
233233
t.localize("test", opts);
234234
return equal(t.text(), "country code success");
235235
});
236+
test("three-letter language code", function() {
237+
var opts, t;
238+
opts = {
239+
language: "ast",
240+
pathPrefix: "lang"
241+
};
242+
t = localizableTagWithRel("p", "basic", {
243+
text: "basic fail"
244+
});
245+
t.localize("test", opts);
246+
return equal(t.text(), "basic success");
247+
});
236248
module("Language optimization");
237249
test("skipping language using string match", function() {
238250
var opts, t;

0 commit comments

Comments
 (0)