diff options
author | Yukai Huang | 2017-03-13 21:32:50 +0800 |
---|---|---|
committer | Yukai Huang | 2017-03-13 21:32:50 +0800 |
commit | 93e41f3a40394f061ca81c8ce119c85611173621 (patch) | |
tree | 20a81f7e77263e05b3d28304f72f4f224d931b0e /public/js/locale.js | |
parent | 9b513f619fe74a579fadd807f86bd38f1049c56b (diff) | |
parent | edb1b4aa0a72ac8b0215211c9dbc54156c3ff91f (diff) |
Merge branch 'master' into cm-refactor
Diffstat (limited to '')
-rw-r--r-- | public/js/locale.js | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/public/js/locale.js b/public/js/locale.js index e6d11cd2..2a2c1814 100644 --- a/public/js/locale.js +++ b/public/js/locale.js @@ -1,26 +1,28 @@ -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()); -}); +/* eslint-env browser, jquery */ +/* global Cookies */ + +var lang = 'en' +var userLang = navigator.language || navigator.userLanguage +var userLangCode = userLang.split('-')[0] +var locale = $('.ui-locale') +var supportLangs = [] +$('.ui-locale option').each(function () { + supportLangs.push($(this).val()) +}) if (Cookies.get('locale')) { - lang = Cookies.get('locale'); + lang = Cookies.get('locale') } else if (supportLangs.indexOf(userLang) !== -1) { - lang = supportLangs[supportLangs.indexOf(userLang)]; + lang = supportLangs[supportLangs.indexOf(userLang)] } else if (supportLangs.indexOf(userLangCode) !== -1) { - lang = supportLangs[supportLangs.indexOf(userLangCode)]; + lang = supportLangs[supportLangs.indexOf(userLangCode)] } -locale.val(lang); -$('select.ui-locale option[value="' + lang + '"]').attr('selected','selected'); +locale.val(lang) +$('select.ui-locale option[value="' + lang + '"]').attr('selected', 'selected') -locale.change(function() { - Cookies.set('locale', $(this).val(), { - expires: 365 - }); - window.location.reload(); -}); +locale.change(function () { + Cookies.set('locale', $(this).val(), { + expires: 365 + }) + window.location.reload() +}) |