Rangappa Tungal
Rangappa Tungal

Reputation: 255

Translate Content in JavaScript an HTML with the Google Translate API

I need to create a button that will be able to toggle the language of a page's content between French and English.

How can I use the Google Translate API for this?

Upvotes: 4

Views: 14252

Answers (1)

HBP
HBP

Reputation: 16053

Does this help :

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

<script>
function googleTranslateElementInit() {
  new google.translate.TranslateElement({
    // here is where you change the language
    pageLanguage: 'en'
  }, 'google_translate_element');
}
</script>

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

Source

Upvotes: 5

Related Questions