jquery 在页面加载时将网站翻译为任何特定语言

k97glaaz  于 2022-11-03  发布在  jQuery
关注(0)|答案(4)|浏览(125)

任何人有任何想法如何翻译成任何语言的网页使用谷歌翻译时,它加载?
我不想要一个下拉菜单,我只是想把网站转换成一个特定的语言,当它加载。我已经尝试了很多事情从http://code.google.com/p/jquery-translate/,但都是徒劳的。任何好的建议将不胜感激。

xzv2uavs

xzv2uavs1#

<!--
  This code will translate page contents automatically (without user input)
  Settings located at line 9, current script will translate english to estonian
-->
<style>#google_translate_element,.skiptranslate{display:none;}body{top:0!important;}</style>
<div id="google_translate_element"></div>
<script>
    function googleTranslateElementInit() {
        new google.translate.TranslateElement({
            pageLanguage: 'en', 
            includedLanguages: 'et', 
            autoDisplay: false
        }, 'google_translate_element');
        var a = document.querySelector("#google_translate_element select");
        a.selectedIndex=1;
        a.dispatchEvent(new Event('change'));
    }
</script>
<script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

从这个要点:https://gist.github.com/artturik/15bed885bcec6faa95eb73acb2e2ae54

x6h2sr28

x6h2sr282#

从Google翻译帮助:
若要创建一个链接来自动翻译启用了Website Translator的页面,而不提示用户,请使用参数#googtrans(en|TARGET_LANG_CODE)
例如,链接|fr)会自动将页面http://translate.google.com/support/翻译成法文。

gdrx4gfi

gdrx4gfi3#

你可以从https://translate.google.com通过给你的网站网址谷歌翻译代码。

就像这样

<div id="google_translate_element"></div><script type="text/javascript">
function googleTranslateElementInit() {
  new google.translate.TranslateElement({pageLanguage: 'ar', layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element');
}
</script><script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
gfttwv5a

gfttwv5a4#

它是当前正在使用工作代码

<!DOCTYPE html>
<html lang="en-US">
<head>
<script type="text/javascript">
function googleTranslateElementInit() {
  new google.translate.TranslateElement({pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element');
}
</script>

<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
<script type="text/javascript" src="//translate.google.com/#en/hi/Hello"></script>
</head>

<style>
body > .skiptranslate {
    //display: none;
}

.goog-te-banner-frame.skiptranslate {
    display: none !important;
    } 
body {
    top: 0px !important; 
    }

@media print {
  #google_translate_element {display: none;}
}
</style>

<body>
<div id="google_translate_element"></div>

<p>This example displays a simple translate button, with no text.</p>
<p>This example displays a simple translate button, with no text.</p>

<div class="notranslate">
<p >This is a paragraph.</p>
<p >
A particle is kept at rest at the top of a sphere of diameter \(42 m\). When disturbed slightly,
it slides down. At what height \( h \) from the bottom, the particle will leave the sphere <br\>
(a) \( 14m \)
(b) \( 16m \)
(c) \( 35m \)
(d) \( 70m \)

</p>
</div>

</body>
</html>

它会翻译你的网页内容。如果你不想翻译任何特定的div内容,只要使用类notranslate。那么谷歌翻译将不会翻译该div内容。

相关问题