给网站加谷歌翻译,搜索引擎一搜一大堆,这里不再赘述。只贴一个申请谷歌翻译的一个地址:
<script>
function googleTranslateElementInit() {
var google_translate_element = document.getElementById('google_translate_element');
var timer = setInterval(function() {
google_translate_element = document.getElementById('google_translate_element');
if (google_translate_element) {
clearInterval(timer);
var langName = navigator.language ? navigator.language.split('-')[0].toLowerCase() : 'en';
new google.translate.TranslateElement({
pageLanguage: langName,
//0,原生select,并且谷歌logo显示在按钮下方。1,原生select,并且谷歌logo显示在右侧。2,完全展开语言列表,适合pc,
layout: /mobile/i.test(navigator.userAgent) ? 0 : 2,
},
'google_translate_element'
);
// 清除图片的请求
img = [].slice.call(document.querySelectorAll('#goog-gt-tt img,#google_translate_element img'));
img.forEach(function(v, i) {
v.src = '';
});
}
}, 300);
}
</script>
<script id="translate_google_js" src="https://g.mbkfw.com/skin/xhdtmubanskin/image/nopic.gif"></script>
调取的地方用 <div id="google_translate_element"></div>