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 badges3 Answers
Reset to default 2Check 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
版权声明:本文标题:javascript - google API translate, only a div into page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741863818a2401779.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论