This repository has been archived by the owner on Jan 4, 2023. It is now read-only.
forked from vaxilu/x-ui
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from foroughi1380/main
Add support for Multi-Language
- Loading branch information
Showing
36 changed files
with
714 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ x-ui-*.tar.gz | |
main | ||
release/ | ||
access.log | ||
.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <ca.length; i++) { | ||
let c = ca[i]; | ||
while (c.charAt(0) == ' ') { | ||
c = c.substring(1); | ||
} | ||
if (c.indexOf(name) == 0) { | ||
return c.substring(name.length, c.length); | ||
} | ||
} | ||
return ""; | ||
} | ||
|
||
function setCookie(cname, cvalue, exdays) { | ||
const d = new Date(); | ||
d.setTime(d.getTime() + (exdays*24*60*60*1000)); | ||
let expires = "expires="+ d.toUTCString(); | ||
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,6 @@ | |
display: none; | ||
} | ||
</style> | ||
<title>{{.title}}</title> | ||
<title>{{ i18n .title}}</title> | ||
</head> | ||
{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.