Translate website to any specific language, on page load

MM2 picture MM2 · Oct 23, 2012 · Viewed 49.1k times · Source

Anybody have any idea how to translate a web page into any language using Google translate when it loads?

I don't want a drop down menu, I just want to convert the website into a specific language when it loads. I have tried many things from http://code.google.com/p/jquery-translate/ but all in vain. Any good suggestions would be appreciated.

Answer

Artur Babyuk picture Artur Babyuk · Jun 5, 2016
<!--
  This code will translate page contents automatically (without user input)
  Settings located at line 9, current script will translate english to estonian
-->
<style>#google_translate_element,.skiptranslate{display:none;}body{top:0!important;}</style>
<div id="google_translate_element"></div>
<script>
    function googleTranslateElementInit() {
        new google.translate.TranslateElement({
            pageLanguage: 'en', 
            includedLanguages: 'et', 
            autoDisplay: false
        }, 'google_translate_element');
        var a = document.querySelector("#google_translate_element select");
        a.selectedIndex=1;
        a.dispatchEvent(new Event('change'));
    }
</script>
<script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

From this gist: https://gist.github.com/artturik/15bed885bcec6faa95eb73acb2e2ae54