I am trying to create a website that shows the selected language page at first visit. On click of the language name, the language name string (eg. French) gets stored in the web/local storage. And when the next time user visits the website, the language string is checked and specific language page is shown. I have written twelve functions for storing the language string on click of anchor tag of each language. Like this:
function english()
{
if(typeof(Storage)!=="undefined")
{
localStorage.clear();
localStorage.language="English";
window.location.reload();
}
}
function french()
{
if(typeof(Storage)!=="undefined")
{
localStorage.clear();
localStorage.language="French";
window.location.href = "french.html";
}
}
Is this method really efficient? I think creating multiple pages for multiple language is good for SEO rather than changing the text string on the fly. Till here when I check the Chrome developers console, the value of the string gets stored. But when I close the tab or the browser window the stored value is gone and the next time it cannot remember the language.
I am checking the language using this code (I have to do it for 12 languages):
window.onload = function() {
if (localStorage.language="Language")
{
window.location.href = "language.html";
}
else if (localStorage.language="English")
{
window.location.href = "eng.html";
}
else if (localStorage.language="French")
{
window.location.href = "french.html";
}
else if (localStorage.language="Spanish")
{
window.location.href = "spanish.html";
}
The code kinda stops after checking the first 'if' condition, true or false it just stops there and doesn't check the 'else if' condition beyond that.
Can someone please help me this?? The sample codes seems to store the value in web storage even after browser close but I cannot replicate it in mine.