使用 Google Translate API 将 JavaScript 中的内容翻译成 HTML
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10426017/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 09:50:50 来源:igfitidea点击:
Translate Content in JavaScript an HTML with the Google Translate API
提问by Rangappa Tungal
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?
我如何为此使用 Google Translate API?
回答by HBP
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>