Translate Content in JavaScript an HTML with the Google Translate API

前端 未结 1 1287
鱼传尺愫
鱼传尺愫 2021-01-19 06:31

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条回答
  • 2021-01-19 07:00

    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

    0 讨论(0)
提交回复
热议问题