DEV Community

Cover image for How to add Google Translate to your website
Federico Navarrete
Federico Navarrete

Posted on • Updated on • Originally published at supernovaic.blogspot.com

 

How to add Google Translate to your website

Sometimes you would like to add to your website a quick widget to allow your users to translate into their language. Google has a simple widget that you can add with some lines of code:

<script>
    function googleTranslateElementInit() {
        new google.translate.TranslateElement(
            //here you add the supported languages like en, es, zh, nl, de, etc.
            {pageLanguage: 'en'},
            'google_translate_element'
        );
    }
</script>
<script src="https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

<div id="google_translate_element"></div>
Enter fullscreen mode Exit fullscreen mode

And that's all.

Follow me at:

LinkedIn YouTube Instagram Cyber Prophets Sharing Your Stories
LinkedIn YouTube Instagram RedCircle Podcast RedCircle Podcast

sponsor me

Top comments (0)

Regex for lazy developers

regex for lazy devs

You know who you are. Sorry for the callout 😆