Html-JavaScriptNo Comments

default thumbnail

Google language translator is used to translate your website in other language. Here is how to use google language translator on your website.

HTML(Translate button)

//place below code where you want to use language switcher button.

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

Google API

//use the below script provided by the google in footer

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

Java Script Function

//use the below javascript function just below the google api 

<script type="text/javascript">
function googleTranslateElementInit() {
  new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
}
</script>

Full code

<!DOCTYPE html>
<html lang="en-US">
<body>

<h1>Google translator for website</h1>

<p>Try below code selecting your language.</p>

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

<script type="text/javascript">
function googleTranslateElementInit() {
  new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
}
</script>

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

</body>
</html>

Be the first to post a comment.

Add a comment