-3
Save guys, I’m trying to change language a site but by Javascript I can not at all.
The way I’ve been trying is as follows. But when I try to re-load the page, the link does not change, does not go out of place. Does anyone know how to fix it or has a better way to do it??
Thank you.
<a href="#eng" data-reload>ENGLISH</a>
<a href="#ita" data-reload>ITALIANO</a>
<p id="hi">
Welcome everyone!
</p>
<script>
//define language reload anchors//
var dataReload = document.querySelectorAll("[data-reload]");
//language translations//
var language = {
eng: {
welcome: "Welcome everyone!"
},
ita: {
welcome: "Benvenuti a tutti!"
}
};
//define language via window hash//
if (window.location.hash) {
if (window.location.hash === "#ita") {
hi.textContent = language.ita.welcome;
}
}
//define language reload onclick illiteration
for (i = 0; i <= dataReload.length; i++) {
dataReload[i].onclick = function() {
location.reload(true);
};
}
</script>