Load website in translated language?

[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>

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer