What is Google translate widget?
The Google Translate widget adds translation functionality to web sites.
This widget enables visitors to translate the content of the website into various languages with just selecting a language.
Now-a-days, Google offers different cloud services for translation.
Adding Google Translate widget to a web page:
1. Add an HTML <div>
element with id="google_translator_div" in your HTML page that you want to translate. This 'div' will contain the Google translate button.
2. Add a JavaScript function named 'translateElement()' inside <script>
element and add the code 'new google.translate.TranslateElement({ pageLanguage: 'en' }, 'google_translator_div');
' to call the google 'TranslateElement()' function. In the function, pageLanguage: 'en'
argument is passed to set English as default language of the page while 'google_translator_div'
is the id of div element to be used as container for Google translate button.
3. Add the following Google translate JavaScript link. In the link, translateElement
is function name you have created earlier passed as parameter.