Skip to content

Commit 0a57427

Browse files
committedOct 13, 2016
Merge branch 'fix-issue-47' of https://github.com/oSoMoN/jquery-localize into oSoMoN-fix-issue-47
* 'fix-issue-47' of https://github.com/oSoMoN/jquery-localize: Update the test expectation to make it unambiguous. When a language-country code was requested, do not fail early if the language only file doesn't exist. Add a failing unit test for #47.
2 parents 89604fb + 5343457 commit 0a57427

6 files changed

+32
-4
lines changed
 

‎dist/jquery.localize.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ http://keith-wood.name/localisation.html
5959
return loadLanguage(pkg, lang, level + 1);
6060
};
6161
errorFunc = function() {
62-
if (options.fallback && options.fallback !== lang) {
62+
if (level === 2 && lang.indexOf('-') > -1) {
63+
return loadLanguage(pkg, lang, level + 1);
64+
} else if (options.fallback && options.fallback !== lang) {
6365
return loadLanguage(pkg, options.fallback);
6466
}
6567
};

‎dist/jquery.localize.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/jquery.localize.coffee

+5-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ do ($ = jQuery) ->
4747
notifyDelegateLanguageLoaded(intermediateLangData)
4848
loadLanguage(pkg, lang, level + 1)
4949
errorFunc = ->
50-
if options.fallback && options.fallback != lang
50+
if level == 2 && lang.indexOf('-') > -1
51+
# the language-only file may not exist, try the language-country file next
52+
# (ref: https://github.com/coderifous/jquery-localize/issues/47)
53+
loadLanguage(pkg, lang, level + 1)
54+
else if options.fallback && options.fallback != lang
5155
loadLanguage(pkg, options.fallback)
5256
ajaxOptions =
5357
url: file

‎test/lang/test-zh-CN.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"basic": "basic success zh-CN"
3+
}

‎test/localize_test.coffee

+7
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ do ($ = jQuery) ->
156156
t.localize("test", opts)
157157
equal t.text(), "basic success"
158158

159+
# Ref: https://github.com/coderifous/jquery-localize/issues/47
160+
test "language-country code with no language-only file", ->
161+
opts = language: "zh-CN", pathPrefix: "lang"
162+
t = localizableTagWithRel("p", "basic", text: "basic fail")
163+
t.localize("test", opts)
164+
equal t.text(), "basic success zh-CN"
165+
159166
module "Language optimization"
160167

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

‎test/localize_test.js

+12
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,18 @@
245245
t.localize("test", opts);
246246
return equal(t.text(), "basic success");
247247
});
248+
test("language-country code with no language-only file", function() {
249+
var opts, t;
250+
opts = {
251+
language: "zh-CN",
252+
pathPrefix: "lang"
253+
};
254+
t = localizableTagWithRel("p", "basic", {
255+
text: "basic fail"
256+
});
257+
t.localize("test", opts);
258+
return equal(t.text(), "basic success zh-CN");
259+
});
248260
module("Language optimization");
249261
test("skipping language using string match", function() {
250262
var opts, t;

0 commit comments

Comments
 (0)
Please sign in to comment.