From db923763574ac308c9e755760b30de1ec0eddf89 Mon Sep 17 00:00:00 2001 From: Haixing Hu Date: Sat, 28 Feb 2015 17:40:16 +0800 Subject: [PATCH 1/5] add the bower configuration --- bower.json | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 bower.json diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..ea90fb0 --- /dev/null +++ b/bower.json @@ -0,0 +1,37 @@ +{ + "name": "jquery-localize", + "version": "0.1.0", + "license": "MIT", + "description": "A jQuery plugin that makes it easy to i18n your static web site.", + "keywords": [ + "jquery", + "localize", + "i18n" + ], + "homepage": "https://github.com/Haixing-Hu/jquery-localize", + "authors": [ + { + "name": "coderifous", + "email": "jim@thegarvin.com" + } + ], + "repository": { + "type": "git", + "url": "git@github.com:Haixing-Hu/jquery-localize.git" + }, + "main": [ + "dist/jquery.localize.js", + "dist/jquery.localize.min.js" + ], + "dependencies": { + "jquery": ">=1.9.0" + }, + "devDependencies": { + "qunit":">=1.11.0" + }, + "ignore": [ + "test", + "libs" + ] +} + From 9c5cc4ac29b3869727ef5314330d70915d2a749e Mon Sep 17 00:00:00 2001 From: Haixing Hu Date: Sun, 8 Mar 2015 09:08:15 +0800 Subject: [PATCH 2/5] fix the issue #47 --- bower.json | 2 +- dist/jquery.localize.js | 3 +++ dist/jquery.localize.min.js | 6 +++--- localize.jquery.json | 2 +- package.json | 2 +- src/jquery.localize.coffee | 3 +++ 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/bower.json b/bower.json index ea90fb0..2d7c0e1 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jquery-localize", - "version": "0.1.0", + "version": "0.1.1", "license": "MIT", "description": "A jQuery plugin that makes it easy to i18n your static web site.", "keywords": [ diff --git a/dist/jquery.localize.js b/dist/jquery.localize.js index e33ce7b..e65e89d 100644 --- a/dist/jquery.localize.js +++ b/dist/jquery.localize.js @@ -64,6 +64,9 @@ http://keith-wood.name/localisation.html return loadLanguage(pkg, lang, level + 1); }; errorFunc = function() { + if (level < 3) { + loadLanguage(pkg, lang, level + 1); + } if (options.fallback && options.fallback !== lang) { return loadLanguage(pkg, options.fallback); } diff --git a/dist/jquery.localize.min.js b/dist/jquery.localize.min.js index 73f1334..d040d04 100644 --- a/dist/jquery.localize.min.js +++ b/dist/jquery.localize.min.js @@ -1,4 +1,4 @@ -/*! Localize - v0.1.0 - 2014-03-04 +/*! Localize - v0.1.0 - 2015-03-08 * https://github.com/coderifous/jquery-localize - * Copyright (c) 2014 coderifous; Licensed MIT */ -!function(a){var b;return b=function(a){return a=a.replace(/_/,"-").toLowerCase(),a.length>3&&(a=a.substring(0,3)+a.substring(3).toUpperCase()),a},a.defaultLanguage=b(navigator.language||navigator.userLanguage),a.localize=function(c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u;return null==d&&(d={}),u=this,g={},f=d.fileExtension||"json",j=function(a,b,c){var e;switch(null==c&&(c=1),c){case 1:return g={},d.loadBase?(e=a+("."+f),h(e,a,b,c)):j(a,b,2);case 2:if(b.length>=2)return e=""+a+"-"+b.substring(0,2)+"."+f,h(e,a,b,c);break;case 3:if(b.length>=5)return e=""+a+"-"+b.substring(0,5)+"."+f,h(e,a,b,c)}},h=function(b,c,e,f){var h,i,k;return null!=d.pathPrefix&&(b=""+d.pathPrefix+"/"+b),k=function(b){return a.extend(g,b),p(g),j(c,e,f+1)},i=function(){return d.fallback&&d.fallback!==e?j(c,d.fallback):void 0},h={url:b,dataType:"json",async:!1,timeout:null!=d.timeout?d.timeout:500,success:k,error:i},"file:"===window.location.protocol&&(h.error=function(b){return k(a.parseJSON(b.responseText))}),a.ajax(h)},p=function(a){return null!=d.callback?d.callback(a,e):e(a)},e=function(b){return a.localize.data[c]=b,u.each(function(){var c,d,e;return c=a(this),d=c.data("localize"),d||(d=c.attr("rel").match(/localize\[(.*?)\]/)[1]),e=t(d,b),null!=e?k(c,d,e):void 0})},k=function(b,c,d){return b.is("input")?n(b,c,d):b.is("img")?m(b,c,d):b.is("optgroup")?o(b,c,d):a.isPlainObject(d)||b.html(d),a.isPlainObject(d)?l(b,d):void 0},n=function(b,c,d){var e;return e=a.isPlainObject(d)?d.value:d,b.is("[placeholder]")?b.attr("placeholder",e):b.val(e)},l=function(a,b){return r(a,"title",b),s(a,"text",b)},o=function(a,b,c){return a.attr("label",c)},m=function(a,b,c){return r(a,"alt",c),r(a,"src",c)},t=function(a,b){var c,d,e,f;for(c=a.split(/\./),d=b,e=0,f=c.length;f>e;e++)a=c[e],d=null!=d?d[a]:null;return d},r=function(a,b,c){return c=t(b,c),null!=c?a.attr(b,c):void 0},s=function(a,b,c){return c=t(b,c),null!=c?a.text(c):void 0},q=function(a){var b;return"string"==typeof a?"^"+a+"$":null!=a.length?function(){var c,d,e;for(e=[],c=0,d=a.length;d>c;c++)b=a[c],e.push(q(b));return e}().join("|"):a},i=b(d.language?d.language:a.defaultLanguage),d.skipLanguage&&i.match(q(d.skipLanguage))||j(c,i,1),u},a.fn.localize=a.localize,a.localize.data={}}(jQuery); \ No newline at end of file + * Copyright (c) 2015 coderifous; Licensed MIT */ +!function(a){var b;return b=function(a){return a=a.replace(/_/,"-").toLowerCase(),a.length>3&&(a=a.substring(0,3)+a.substring(3).toUpperCase()),a},a.defaultLanguage=b(navigator.language||navigator.userLanguage),a.localize=function(c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u;return null==d&&(d={}),u=this,g={},f=d.fileExtension||"json",j=function(a,b,c){var e;switch(null==c&&(c=1),c){case 1:return g={},d.loadBase?(e=a+("."+f),h(e,a,b,c)):j(a,b,2);case 2:if(b.length>=2)return e=""+a+"-"+b.substring(0,2)+"."+f,h(e,a,b,c);break;case 3:if(b.length>=5)return e=""+a+"-"+b.substring(0,5)+"."+f,h(e,a,b,c)}},h=function(b,c,e,f){var h,i,k;return null!=d.pathPrefix&&(b=""+d.pathPrefix+"/"+b),k=function(b){return a.extend(g,b),p(g),j(c,e,f+1)},i=function(){return 3>f&&j(c,e,f+1),d.fallback&&d.fallback!==e?j(c,d.fallback):void 0},h={url:b,dataType:"json",async:!1,timeout:null!=d.timeout?d.timeout:500,success:k,error:i},"file:"===window.location.protocol&&(h.error=function(b){return k(a.parseJSON(b.responseText))}),a.ajax(h)},p=function(a){return null!=d.callback?d.callback(a,e):e(a)},e=function(b){return a.localize.data[c]=b,u.each(function(){var c,d,e;return c=a(this),d=c.data("localize"),d||(d=c.attr("rel").match(/localize\[(.*?)\]/)[1]),e=t(d,b),null!=e?k(c,d,e):void 0})},k=function(b,c,d){return b.is("input")?n(b,c,d):b.is("img")?m(b,c,d):b.is("optgroup")?o(b,c,d):a.isPlainObject(d)||b.html(d),a.isPlainObject(d)?l(b,d):void 0},n=function(b,c,d){var e;return e=a.isPlainObject(d)?d.value:d,b.is("[placeholder]")?b.attr("placeholder",e):b.val(e)},l=function(a,b){return r(a,"title",b),s(a,"text",b)},o=function(a,b,c){return a.attr("label",c)},m=function(a,b,c){return r(a,"alt",c),r(a,"src",c)},t=function(a,b){var c,d,e,f;for(c=a.split(/\./),d=b,e=0,f=c.length;f>e;e++)a=c[e],d=null!=d?d[a]:null;return d},r=function(a,b,c){return c=t(b,c),null!=c?a.attr(b,c):void 0},s=function(a,b,c){return c=t(b,c),null!=c?a.text(c):void 0},q=function(a){var b;return"string"==typeof a?"^"+a+"$":null!=a.length?function(){var c,d,e;for(e=[],c=0,d=a.length;d>c;c++)b=a[c],e.push(q(b));return e}().join("|"):a},i=b(d.language?d.language:a.defaultLanguage),d.skipLanguage&&i.match(q(d.skipLanguage))||j(c,i,1),u},a.fn.localize=a.localize,a.localize.data={}}(jQuery); \ No newline at end of file diff --git a/localize.jquery.json b/localize.jquery.json index 3302442..b2b9e39 100644 --- a/localize.jquery.json +++ b/localize.jquery.json @@ -2,7 +2,7 @@ "name": "jquery.localize", "title": "Localize", "description": "A jQuery plugin that makes it easy to i18n your static web site.", - "version": "0.1.0", + "version": "0.1.1", "homepage": "https://github.com/coderifous/jquery-localize", "author": { "name": "coderifous", diff --git a/package.json b/package.json index ccbe2a6..1955d0c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jquery-localize", - "version": "0.0.0-ignored", + "version": "0.1.1", "engines": { "node": ">= 0.8.0" }, diff --git a/src/jquery.localize.coffee b/src/jquery.localize.coffee index 723e9a3..106f7b6 100644 --- a/src/jquery.localize.coffee +++ b/src/jquery.localize.coffee @@ -49,6 +49,9 @@ do ($ = jQuery) -> notifyDelegateLanguageLoaded(intermediateLangData) loadLanguage(pkg, lang, level + 1) errorFunc = -> + # by Haixing Hu: load the next level even if the higher level failed. + if level < 3 + loadLanguage(pkg, lang, level + 1) if options.fallback && options.fallback != lang loadLanguage(pkg, options.fallback) ajaxOptions = From f37ea239af040ab8eeed5d6b2ccc4439d88d98de Mon Sep 17 00:00:00 2001 From: Haixing Hu Date: Sun, 8 Mar 2015 09:22:44 +0800 Subject: [PATCH 3/5] add unit test for the patch of issue #47 --- dist/jquery.localize.min.js | 2 +- examples/language_country_code_directly.html | 24 ++++++++++++++++++++ test/lang/test-zh-CN.json | 3 +++ test/localize_test.coffee | 6 +++++ test/localize_test.js | 12 ++++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 examples/language_country_code_directly.html create mode 100644 test/lang/test-zh-CN.json diff --git a/dist/jquery.localize.min.js b/dist/jquery.localize.min.js index d040d04..ca7476f 100644 --- a/dist/jquery.localize.min.js +++ b/dist/jquery.localize.min.js @@ -1,4 +1,4 @@ -/*! Localize - v0.1.0 - 2015-03-08 +/*! Localize - v0.1.1 - 2015-03-08 * https://github.com/coderifous/jquery-localize * Copyright (c) 2015 coderifous; Licensed MIT */ !function(a){var b;return b=function(a){return a=a.replace(/_/,"-").toLowerCase(),a.length>3&&(a=a.substring(0,3)+a.substring(3).toUpperCase()),a},a.defaultLanguage=b(navigator.language||navigator.userLanguage),a.localize=function(c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u;return null==d&&(d={}),u=this,g={},f=d.fileExtension||"json",j=function(a,b,c){var e;switch(null==c&&(c=1),c){case 1:return g={},d.loadBase?(e=a+("."+f),h(e,a,b,c)):j(a,b,2);case 2:if(b.length>=2)return e=""+a+"-"+b.substring(0,2)+"."+f,h(e,a,b,c);break;case 3:if(b.length>=5)return e=""+a+"-"+b.substring(0,5)+"."+f,h(e,a,b,c)}},h=function(b,c,e,f){var h,i,k;return null!=d.pathPrefix&&(b=""+d.pathPrefix+"/"+b),k=function(b){return a.extend(g,b),p(g),j(c,e,f+1)},i=function(){return 3>f&&j(c,e,f+1),d.fallback&&d.fallback!==e?j(c,d.fallback):void 0},h={url:b,dataType:"json",async:!1,timeout:null!=d.timeout?d.timeout:500,success:k,error:i},"file:"===window.location.protocol&&(h.error=function(b){return k(a.parseJSON(b.responseText))}),a.ajax(h)},p=function(a){return null!=d.callback?d.callback(a,e):e(a)},e=function(b){return a.localize.data[c]=b,u.each(function(){var c,d,e;return c=a(this),d=c.data("localize"),d||(d=c.attr("rel").match(/localize\[(.*?)\]/)[1]),e=t(d,b),null!=e?k(c,d,e):void 0})},k=function(b,c,d){return b.is("input")?n(b,c,d):b.is("img")?m(b,c,d):b.is("optgroup")?o(b,c,d):a.isPlainObject(d)||b.html(d),a.isPlainObject(d)?l(b,d):void 0},n=function(b,c,d){var e;return e=a.isPlainObject(d)?d.value:d,b.is("[placeholder]")?b.attr("placeholder",e):b.val(e)},l=function(a,b){return r(a,"title",b),s(a,"text",b)},o=function(a,b,c){return a.attr("label",c)},m=function(a,b,c){return r(a,"alt",c),r(a,"src",c)},t=function(a,b){var c,d,e,f;for(c=a.split(/\./),d=b,e=0,f=c.length;f>e;e++)a=c[e],d=null!=d?d[a]:null;return d},r=function(a,b,c){return c=t(b,c),null!=c?a.attr(b,c):void 0},s=function(a,b,c){return c=t(b,c),null!=c?a.text(c):void 0},q=function(a){var b;return"string"==typeof a?"^"+a+"$":null!=a.length?function(){var c,d,e;for(e=[],c=0,d=a.length;d>c;c++)b=a[c],e.push(q(b));return e}().join("|"):a},i=b(d.language?d.language:a.defaultLanguage),d.skipLanguage&&i.match(q(d.skipLanguage))||j(c,i,1),u},a.fn.localize=a.localize,a.localize.data={}}(jQuery); \ No newline at end of file diff --git a/examples/language_country_code_directly.html b/examples/language_country_code_directly.html new file mode 100644 index 0000000..459549a --- /dev/null +++ b/examples/language_country_code_directly.html @@ -0,0 +1,24 @@ + + + + + + + Localize Test + + + + + +

Test localization...

+

It failed :(

+ + + + diff --git a/test/lang/test-zh-CN.json b/test/lang/test-zh-CN.json new file mode 100644 index 0000000..91b826e --- /dev/null +++ b/test/lang/test-zh-CN.json @@ -0,0 +1,3 @@ +{ + "message": "language-country code success" +} \ No newline at end of file diff --git a/test/localize_test.coffee b/test/localize_test.coffee index 62cfb1d..435df5f 100644 --- a/test/localize_test.coffee +++ b/test/localize_test.coffee @@ -138,6 +138,12 @@ do ($ = jQuery) -> t.localize("test", opts) equal t.text(), "country code success" + test "load language-country code json file directly", -> + opts = language: "zh-CN", pathPrefix: "lang" + t = localizableTagWithRel("p", "message", text: "language-country code fail") + t.localize("test", opts) + equal t.text(), "language-country code success" + module "Language optimization" test "skipping language using string match", -> diff --git a/test/localize_test.js b/test/localize_test.js index 476f505..02ccfd5 100644 --- a/test/localize_test.js +++ b/test/localize_test.js @@ -215,6 +215,18 @@ t.localize("test", opts); return equal(t.text(), "country code success"); }); + test("load language-country code json file directly", function() { + var opts, t; + opts = { + language: "zh-CN", + pathPrefix: "lang" + }; + t = localizableTagWithRel("p", "message", { + text: "language-country code fail" + }); + t.localize("test", opts); + return equal(t.text(), "language-country code success"); + }); module("Language optimization"); test("skipping language using string match", function() { var opts, t; From 1351dff32f7f5a51a16dca60f2622bd0d9cc82e6 Mon Sep 17 00:00:00 2001 From: Haixing Hu Date: Sun, 26 Jul 2015 22:40:25 +0800 Subject: [PATCH 4/5] fix the bower.json --- bower.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bower.json b/bower.json index 2d7c0e1..ca35010 100644 --- a/bower.json +++ b/bower.json @@ -20,8 +20,7 @@ "url": "git@github.com:Haixing-Hu/jquery-localize.git" }, "main": [ - "dist/jquery.localize.js", - "dist/jquery.localize.min.js" + "dist/jquery.localize.js" ], "dependencies": { "jquery": ">=1.9.0" From 48087725265a700d183c18ea9a48d0bbec5da7bf Mon Sep 17 00:00:00 2001 From: Haixing Hu Date: Sun, 26 Jul 2015 22:41:51 +0800 Subject: [PATCH 5/5] increase version number --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index ca35010..eeb27d0 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jquery-localize", - "version": "0.1.1", + "version": "0.1.2", "license": "MIT", "description": "A jQuery plugin that makes it easy to i18n your static web site.", "keywords": [