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

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

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');
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742369087a4430895.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信