• Resolved 3C's

    (@cccnate)


    Greetings, using Gtranslate is it possible to translate a site when it first loads to a different language? I would like our site loaded in Spanish, and only translated to English if a user chooses so. TIA.

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Load website in translated language?’ is closed to new replies.