Google API translator. How can I translate only one DIV?

坚强是说给别人听的谎言 提交于 2019-12-20 05:44:11

问题


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>

回答1:


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>



回答2:


Solved with this function:

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


来源:https://stackoverflow.com/questions/24983367/google-api-translator-how-can-i-translate-only-one-div

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!