Traditional Culture Encyclopedia - Traditional culture - How to realize bilingual switching of html pages
How to realize bilingual switching of html pages
By: popular frameworks such as vue.js angular are not used in the front end, so pure html cannot refer to constants defined in js?
Use jquery to assign values (maintain two template (Chinese and English) interfaces) and go out directly.
Scheme: adopt /coderifus/jquery-localize/? A localization plugin?
A jQuery plug-in makes it easy to internationalize your website.
Steps:?
1 html
& lt! DOCTYPE & gt
& lthtml? lang="en " >
& lthead & gt
& ltmeta? e? Are you online? chgLang "? +? Name? +? Value);
location . reload();
}
Function? SetCookie (name, value)? {
var? How many days? =? 30; ? //This? Cookies? Will it be saved? 30? sky
var? exp? =? New? date(); ? //New? Date ("1feb? 3 1,? 9998");
exp.setTime(exp.getTime()? +? How many days? *? 24? *? 60? *? 60? *? 1000);
document.cookie? =? Name? +? "="? +? Escape (value)? +? "; expires=? +? exp . togmtstring();
}
Function? getCookie(name){? //Take the cookies function
var? arr? =? Document.cookie.match (new? RegExp("(^|? )"? +? Name? +? "=([^; ]*)(; |$)"));
What if? (arr? ! =? null)? Return? unescape(arr[2]);
Return? empty
}
$(function()? {
var? uulanguage? =? (navigator.language? ||? navigator.browserLanguage)。 toLowerCase();
Console.log ("Come? Are you online? Are you ready? +? uulanguage);
What if? (uulanguage.indexOf("en ")? & gt? - 1)? {
$ ("[data localization]"). Localization ("text", {/* * main code * *? jquery.localize.js? The underlying implementation exchange logic
Path prefix:? Lang,
Language:? "En"
});
Console.log ("Come? Are you online? en”);
}? Or what? What if? (uulanguage.indexOf("ja ")? & gt? - 1)? {
$ ("[data localization]"). Localization ("text", {
Path prefix:? Lang,
Language:? “ja”
});
Console.log ("Come? Are you online? ja”);
}? Or what? {
$ ("[data localization]"). Localization ("text", {
Path prefix:? Lang,
Language:? "En"
});
Console.log ("Come? Are you online? Moran? en”);
};
//Select the language according to the cookie
What if? (getCookie(name)? ! =? "")? {
What if? (getCookie(name)? ==? “ja”)? {
$ ("[data localization]"). Localization ("text", {
Path prefix:? Lang,
Language:? “ja”
});
Console.log ("Come? Are you online? Cookies? ja”);
}
What if? (getCookie(name)? ==? “en”)? {
$ ("[data localization]"). Localization ("text", {
Path prefix:? Lang,
Language:? "En"
});
Console.log ("Come? Are you online? Cookies? en”);
}
}
});
- Previous article:What are some good mooncakes around the country? Can you recommend a few?
- Next article:What is a printing dot?
- Related articles
- A summary of the theme activities of loving the motherland and hometown
- Introduction to Chinatown in Bangkok
- Crosstalk at the Year of the Rooster Lantern Festival
- Business administration professional knowledge?
- Method for making vinegar sparerib
- What are the requirements for applying for a publication business license?
- Which university in China has a strong administrative major?
- How to pronounce Spring Festival words?
- Wenha how to make delicious
- Why are you afraid of dancing lion and big head Buddha since childhood?