From b9c59c454d68e35708f64703a423930b99075cab Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Fri, 19 Aug 2016 11:49:24 +0800 Subject: Add support of i18n with related patches and support "en" and "zh" locales for now --- public/js/locale.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 public/js/locale.js (limited to 'public/js/locale.js') 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 -- cgit v1.2.3