DEV Community

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

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

2

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

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs