google-translate - 如何让谷歌翻译的部分语言下拉列表工作?

标签 google-translate

我正在尝试使用谷歌翻译来翻译用户评论。我正在使用官方向导 (http://translate.google.com/translate_tools) 生成 java 脚本和 html 代码:

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


<div class="goog-trans-section">
<div class="goog-trans-control">
</div>
some text in some language
</div>

我不想翻译整个页面,而只想翻译评论。不幸的是,为部分翻译生成的代码没有用于语言选择的下拉框。有人知道如何实现吗?我尝试添加 includedLanguages: 'en,fr,de,ru',到 java 脚本代码,但它没有帮助。

最佳答案

super 简单的事情就是使用下面的步骤。
1. 在要显示翻译下拉列表的位置添加以下代码。

<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>
  • 将 class="notranslate"添加到正文标签
  • 将 class="translate"添加到您要由 google translate 翻译的部分。
  • 关于google-translate - 如何让谷歌翻译的部分语言下拉列表工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8358921/

    相关文章:

    java - 如何在 Android Studio 中使用谷歌云翻译 API?

    python - google.auth.exceptions.DefaultCredentialsError :

    python - GoogleTrans Python 不翻译

    android - Google Cloud Translation API 请求缺少有效的 API key

    c# - 如何从角色中获取数据

    ruby-on-rails - Ruby on Rails 的 Google 翻译

    php - 使用谷歌翻译 API 翻译 PHP $string

    javascript - 我想知道 Google 的网站翻译器可以在我们的网站上免费使用吗?在我们的网站上使用它还有其他问题吗?

    c# - 如何在 C# winforms 中翻译文本

    android - 使用 Google Translate API for Android 时如何返回撇号?