Html 谷歌翻译在我的网站上

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6967445/
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-08-29 09:55:38  来源:igfitidea点击:

Google translate on my website

htmlgoogle-translate

提问by vlevsha

I'm trying to embed Google Translate snippet in my website, but for some reason it is not even displayed. I go here: Google tools

我试图在我的网站中嵌入谷歌翻译片段,但由于某种原因它甚至没有显示。我去这里: 谷歌工具

Copy this:

复制这个:

<div id="google_translate_element"></div>
<script>
   function googleTranslateElementInit() {
      new google.translate.TranslateElement({
         pageLanguage: 'en'
      }, 'google_translate_element');
   }
</script>
<script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

Paste it to my webpage. And I don't see it there.

粘贴到我的网页上。我在那里看不到它。

What am I missing? Some HTML maybe?

我错过了什么?也许是一些 HTML?

回答by Maksym Kozlenko

Here is a working example. I think you are missing "&ug=section&hl={LANGUAGE}" parameters:

这是一个工作示例。我认为您缺少“&ug=section&hl={LANGUAGE}”参数:

My Page Тестирование

我的页面 Тестирование

<script>
function googleSectionalElementInit() {
  new google.translate.SectionalElement({
    sectionalNodeClassName: 'translate',
    controlNodeClassName: 'translate_control',
    background: '#f4fa58'
  }, 'google_sectional_element');
}
</script>
<script src="//translate.google.com/translate_a/element.js?cb=googleSectionalElementInit&ug=section&hl=en"></script>

http://jsfiddle.net/maxim75/H3Wkr/- working example

http://jsfiddle.net/maxim75/H3Wkr/- 工作示例

回答by freeworlder

In the HTML, the 'control' class element needs to be nested in the 'section' element. :)

在 HTML 中,'control' 类元素需要嵌套在 'section' 元素中。:)