Translate Content in JavaScript an HTML with the Google Translate API

笑着哭i 提交于 2019-12-04 04:33:12

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/10426017/translate-content-in-javascript-an-html-with-the-google-translate-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!