One-KVM/web/share/js/i18n/i18n.js
2024-08-12 20:58:48 +08:00

67 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* cookie存储用户选取的值 */
function setCookie (name, value)
{
/* 设置名称为name,值为value的Cookie */
var expdate = new Date();
/* 计算时间,30天后过期 */
expdate.setTime(expdate.getTime() + 30 * 24 * 60 * 60 * 1000);
document.cookie = name + "=" + value + "; expires=" + expdate.toGMTString() + "; path=/" + ";SameSite=Lax";
/* 即document.cookie= name+"="+value+";path=/"; 时间可以不要,但路径(path)必须要填写因为JS的默认路径是当前页如果不填此cookie只在当前页面生效 */
}
/* 获取cookie */
function getCookie(name)
{
if (document.cookie.length > 0)
{
start = document.cookie.indexOf(name + "=")
if (start != -1)
{
start = start + name.length + 1
end = document.cookie.indexOf(";", start)
if (end == -1) end = document.cookie.length
return unescape(document.cookie.substring(start, end))
}
}
return ""
}
/**
* 设置语言类型: 默认为中文
*/
var i18nLanguage = "cn";
$(document).ready(function() {
/* 首先获取用户选择过的语言 */
if (getCookie('userLanguage')) {
i18nLanguage = getCookie('userLanguage');
}
$("[i18n]").i18n({
defaultLang: i18nLanguage,
filePath: "/share/i18n/",
filePrefix: "i18n_",
fileSuffix: "",
forever: true,
callback: function() {
}
});
/*切换为中文 - 按钮*/
$(".chinese").click(function() {
$("[i18n]").i18n({
defaultLang: "cn",
filePath: "/share/i18n/"
});
setCookie('userLanguage', "cn")
});
/*切换为英文 - 按钮*/
$(".english").click(function() {
$("[i18n]").i18n({
defaultLang: "en",
filePath: "/share/i18n/"
});
setCookie('userLanguage', "en")
});
});