diff --git a/.gitignore b/.gitignore index 419da08b..63ca6b69 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ x-ui-*.tar.gz main release/ access.log +.cache diff --git a/web/assets/js/langs.js b/web/assets/js/langs.js new file mode 100644 index 00000000..be7dd164 --- /dev/null +++ b/web/assets/js/langs.js @@ -0,0 +1,79 @@ +supportLangs = [ + { + name : "English", + value : "en-US", + icon : "🇺🇸" + }, + { + name : "汉语", + value : "zh-Hans", + icon : "🇨🇳" + }, +] + +function getLang(){ + let lang = getCookie('lang') + + if (! lang){ + if (window.navigator){ + lang = window.navigator.language || window.navigator.userLanguage; + + if (isSupportLang(lang)){ + setCookie('lang' , lang , 150) + }else{ + setCookie('lang' , 'en-US' , 150) + window.location.reload(); + } + }else{ + setCookie('lang' , 'en-US' , 150) + window.location.reload(); + } + } + + return lang; +} + +function setLang(lang){ + + if (!isSupportLang(lang)){ + lang = 'en-US'; + } + + setCookie('lang' , lang , 150) + window.location.reload(); +} + +function isSupportLang(lang){ + for (l of supportLangs){ + if (l.value === lang){ + return true; + } + } + + return false; +} + + + +function getCookie(cname) { + let name = cname + "="; + let decodedCookie = decodeURIComponent(document.cookie); + let ca = decodedCookie.split(';'); + for(let i = 0; i - {{.title}} + {{ i18n .title}} {{end}} \ No newline at end of file diff --git a/web/html/common/js.html b/web/html/common/js.html index b8ee57b2..d400196b 100644 --- a/web/html/common/js.html +++ b/web/html/common/js.html @@ -14,6 +14,7 @@ +