Add Google Translate to your Website

Add Google Translate to your Website | Code Architects

Google Translate is a multilingual neural machine translation tool developed by Google that allows users to translate text, documents, and webpages between languages. It has a website interface, an Android and iOS mobile app, and an API that developers can use to create browser extensions and software apps.

The pros of Google Translate:

  • It’s free
  • It’s fast
  • It’s convenient

Add Google Translate to your website

Add this code to the website <head>

<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

You need to add a element where the script can load the translate dropdown. So, add a <div> with id google_translate_element

<div id="google_translate_element"></div>

Finally, Add a JavaScript function to enable & execute the Translate load events

function googleTranslateElementInit() {
    new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element')
}

You can view the live preview here.

Read our other blogs

Thank you for reading the article. 😊

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

1 × 4 =