summaryrefslogtreecommitdiff
path: root/public/js/locale.js
blob: e6d11cd2808fca6b151f6a0e9ed5aa905d94b442 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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);
$('select.ui-locale option[value="' + lang + '"]').attr('selected','selected');

locale.change(function() {
    Cookies.set('locale', $(this).val(), {
        expires: 365
    });
    window.location.reload();
});