Jason Cole
Jason Cole

Reputation: 51

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

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>

Upvotes: 1

Views: 6194

Answers (2)

Spy
Spy

Reputation: 61

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>

Upvotes: 6

Jason Cole
Jason Cole

Reputation: 51

Solved with this function:

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

Upvotes: 1

Related Questions