admin管理员组

文章数量:1308567

I have an HTML page, and I would use Google Translate to translate only a div into my page.

<div id="google_translate_element"></div><script>
function googleTranslateElementInit() {
  new google.translate.TranslateElement({pageLanguage: 'it'}, 'google_translate_element');
}
</script><script src=".js?cb=googleTranslateElementInit"></script>

With this code, google translate everything in the page. But if I wanna translate only a piece. How I can do it?

Thanks!

I have an HTML page, and I would use Google Translate to translate only a div into my page.

<div id="google_translate_element"></div><script>
function googleTranslateElementInit() {
  new google.translate.TranslateElement({pageLanguage: 'it'}, 'google_translate_element');
}
</script><script src="https://translate.google./translate_a/element.js?cb=googleTranslateElementInit"></script>

With this code, google translate everything in the page. But if I wanna translate only a piece. How I can do it?

Thanks!

Share Improve this question edited Jun 17, 2019 at 6:49 Samson 3521 silver badge13 bronze badges asked Dec 14, 2009 at 10:50 Tommaso TaruffiTommaso Taruffi 9,2529 gold badges45 silver badges59 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

Check the examples at Google AJAX Language API.

google.language.translate("Hello world", "en", "es", function(result) {
  if (!result.error) {
    var container = document.getElementById("translation");
    container.innerHTML = result.translation;
  }
});

use innerHTML to get hold of the contents of your DIV. You may have to strip out formatting first, though.

ok, but how to open any named <div> of a internet web page in my page with <iframe> tag? Is it possible in general, not to display (in iframe) the whole page, but only the part of it (without balast arround)?

I know e.g. this for whole pages :

<div>
  <iframe src ="http://www.colosseum.cz/vzdelavani-a-informace/zpravy" width="98%" height="600" style="border: 3px;">
    <p>unsupported</p>
  </iframe> 
</div>

If you want to continue using the script instead of the API. You can add a notranslate class to all elements that you don't want translated.

You can try it here https://www.w3schools./howto/tryit.asp?filename=tryhow_google_translate

Try changing the h1 tag to

<h1 class="notranslate">My Web Page</h1>

Answer found here https://laracasts./discuss/channels/laravel/translating-only-a-portion-of-page

本文标签: javascriptgoogle API translateonly a div into pageStack Overflow