diff options
author | Wu Cheng-Han | 2016-08-19 11:49:24 +0800 |
---|---|---|
committer | Wu Cheng-Han | 2016-08-19 11:49:24 +0800 |
commit | b9c59c454d68e35708f64703a423930b99075cab (patch) | |
tree | 35afc40b67c86c17d291b482cd52ae2417c82fb3 /public/js | |
parent | 87f4d05e8e8f36ac276cd85601cabc1fbb7efc2c (diff) |
Add support of i18n with related patches and support "en" and "zh" locales for now
Diffstat (limited to 'public/js')
-rw-r--r-- | public/js/cover.js | 2 | ||||
-rw-r--r-- | public/js/locale.js | 24 |
2 files changed, 25 insertions, 1 deletions
diff --git a/public/js/cover.js b/public/js/cover.js index c97bd256..f3533826 100644 --- a/public/js/cover.js +++ b/public/js/cover.js @@ -291,7 +291,7 @@ $(".ui-logout").click(function () { var filtertags = []; $(".ui-use-tags").select2({ - placeholder: 'Select tags...', + placeholder: $(".ui-use-tags").attr('placeholder'), multiple: true, data: function () { return { diff --git a/public/js/locale.js b/public/js/locale.js new file mode 100644 index 00000000..6fe7fdb6 --- /dev/null +++ b/public/js/locale.js @@ -0,0 +1,24 @@ +var lang = "en"; +var userLang = navigator.language || navigator.userLanguage; +var userLangCode = userLang.split('-')[0]; +var userCountryCode = userLang.split('-')[1]; +var locale = $('.ui-locale'); +var supportLangs = []; +$(".ui-locale option").each(function() { + supportLangs.push($(this).val()); +}); +if (Cookies.get('locale')) { + lang = Cookies.get('locale'); +} else if (supportLangs.indexOf(userLang) !== -1) { + lang = supportLangs[supportLangs.indexOf(userLang)]; +} else if (supportLangs.indexOf(userLangCode) !== -1) { + lang = supportLangs[supportLangs.indexOf(userLangCode)]; +} + +locale.val(lang); +locale.change(function() { + Cookies.set('locale', $(this).val(), { + expires: 365 + }); + window.location.reload(); +});
\ No newline at end of file |