/*
    Localization
*/
let languages = ['en', 'zh'];
let languageNames = {
    'en': 'English',
    'zh': '中文（正體）'
};

//Initialize the i18n dom library
var i18n = domI18n({
    selector: '[i18n]',
    separator: ' // ',
    languages: languages,
    defaultLanguage: 'en'
});

$(document).ready(function(){
    let userLang = navigator.language || navigator.userLanguage;
    console.log("User language: " + userLang);
    userLang = userLang.split("-")[0];
    if (!languages.includes(userLang)) {
        userLang = 'en';
    }
    i18n.changeLanguage(userLang);
});

function setCurrentLanguage(newLanguage){
    let languageName = languageNames[newLanguage];
    $("#currentLanguage").html(languageName);
    i18n.changeLanguage(newLanguage);
}