[ad_1]
Thread Starter
3C’s
(@cccnate)
I was given the following script by support to add to the footer.php file. Supposed to translate on load, but all it does is change to menu link to Spanish, but the site content does not translate until clicking on the link.
<script> if (typeof(Storage) !== "undefined") {
if (localStorage.getItem("ChangeLanguageFirstTime") === null) { setTimeout(function() {
const element = document.querySelector('a[data-gt-lang="es"]');
if (element) {
element.click();
localStorage.setItem("ChangeLanguageFirstTime", true);
}
else {
console.error('Element not found!'); } }, 3000);
}
} else {
console.error('localStorage not supported in this browser!');
}
</script>
Thread Starter
3C’s
(@cccnate)
FYI – used this script instead in footer.php and it seems to work:
<script>
if(localStorage.getItem("ChangeLanguageFirstTime") === null) {
document.cookie="googtrans=/en/es";
localStorage.setItem("ChangeLanguageFirstTime", true);
}
</script>