最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google API translator. How can I translate only one DIV? - Stack Overflow

programmeradmin1浏览0评论

How can I modify this code to translate the only one container on page with id #lyrics?

<div id="google_translate_element"></div>
<script>
    function googleTranslateElementInit() {
        new google.translate.TranslateElement({pageLanguage: 'en', includedLanguages: 'ru', layout: google.translate.TranslateElement.InlineLayout.SIMPLE, autoDisplay: false, multilanguagePage: true}, 'google_translate_element');
    }
</script>

How can I modify this code to translate the only one container on page with id #lyrics?

<div id="google_translate_element"></div>
<script>
    function googleTranslateElementInit() {
        new google.translate.TranslateElement({pageLanguage: 'en', includedLanguages: 'ru', layout: google.translate.TranslateElement.InlineLayout.SIMPLE, autoDisplay: false, multilanguagePage: true}, 'google_translate_element');
    }
</script>
Share Improve this question edited Jul 27, 2014 at 17:14 Kartikeya Khosla 18.9k8 gold badges45 silver badges70 bronze badges asked Jul 27, 2014 at 17:06 Jason ColeJason Cole 511 silver badge10 bronze badges 3
  • ok, I'm replace 'google_translate_element' to 'lyrics', but I have the same result – Jason Cole Commented Jul 27, 2014 at 17:17
  • Sorry. Take a look at this answer. – Halvor Holsten Strand Commented Jul 27, 2014 at 17:22
  • I've seen this answer, but I can't apply this to my code, can you help me with this? – Jason Cole Commented Jul 27, 2014 at 17:25
Add a ment  | 

2 Answers 2

Reset to default 6

you can add class call notranslate into the body or the meta tag of the class then add the class translate into the div whom you want to translate its poor approach but it sure do you wok e.g

<body class="notranslate">

<h1>no translate paragraph</h1>

<h1 class="translate"> i want to translate the line</h1>
</body>

Solved with this function:

function googleSectionalElementInit() {
  new google.translate.SectionalElement({
    sectionalNodeClassName: 'lyrics',
    controlNodeClassName: 'translate-lyrics',
    background: 'trasparent'
  }, 'google_sectional_element');
}
发布评论

评论列表(0)

  1. 暂无评论