使用Google Translate API在JavaScript中翻译HTML内容 [英] Translate Content in JavaScript an HTML with the Google Translate API
本文介绍了使用Google Translate API在JavaScript中翻译HTML内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要创建一个按钮,以便能够在法语和英语之间切换页面内容的语言。
I need to create a button that will be able to toggle the language of a page's content between French and English.
如何使用Google Translate API这个?
How can I use the Google Translate API for this?
推荐答案
这有用吗:
<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>
这篇关于使用Google Translate API在JavaScript中翻译HTML内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文