2017-03-08 18:41:05 +00:00
|
|
|
/* 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())
|
|
|
|
})
|
2016-08-19 03:49:24 +00:00
|
|
|
if (Cookies.get('locale')) {
|
2017-03-08 18:41:05 +00:00
|
|
|
lang = Cookies.get('locale')
|
2017-10-17 02:54:52 +00:00
|
|
|
if (lang === 'zh') {
|
|
|
|
lang = 'zh-TW'
|
|
|
|
}
|
2016-08-19 03:49:24 +00:00
|
|
|
} else if (supportLangs.indexOf(userLang) !== -1) {
|
2017-03-08 18:41:05 +00:00
|
|
|
lang = supportLangs[supportLangs.indexOf(userLang)]
|
2016-08-19 03:49:24 +00:00
|
|
|
} else if (supportLangs.indexOf(userLangCode) !== -1) {
|
2017-03-08 18:41:05 +00:00
|
|
|
lang = supportLangs[supportLangs.indexOf(userLangCode)]
|
2016-08-19 03:49:24 +00:00
|
|
|
}
|
|
|
|
|
2017-03-08 18:41:05 +00:00
|
|
|
locale.val(lang)
|
|
|
|
$('select.ui-locale option[value="' + lang + '"]').attr('selected', 'selected')
|
2016-10-23 03:38:17 +00:00
|
|
|
|
2017-03-08 18:41:05 +00:00
|
|
|
locale.change(function () {
|
|
|
|
Cookies.set('locale', $(this).val(), {
|
|
|
|
expires: 365
|
|
|
|
})
|
|
|
|
window.location.reload()
|
|
|
|
})
|