Search code examples
javascripthtmlgoogle-translatetranslate

Google translate - translate whole page at once


I'm using standart API for translate my page (google.translate.TranslateElement)

<script>
            function googleTranslateElementInit() {
                // {pageLanguage: "es"},
                new google.translate.TranslateElement(
                    'google_translate_element'
                );
            }
        </script>
        <script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

I know that this element translate only some part of HTML page and when user scroll down - translate the rest of page. So question is - can i translate whole page at once? P.S. sorry for my english


Solution

  • So, this is really not solution, but ugly hack, but maybe it save time for somebody: You can add hidden block of text in start of page (not use visibility: hidden or display: none, this won't work)

    <div id="translateBlockHidden" style="position: absolute; opacity: 0; font-size: 0; pointer-events:none"></div>
    

    Put all text that should be translated in this element

    Then after translate replace all translate text from #translateBlockHidden to block that should be translated.