谷歌翻译不隐藏 [英] Google Translate isn't Hidden

查看:430
本文介绍了谷歌翻译不隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

选择了Google Translate Widget的自动版本后,如果我的浏览器与网站语言相同,我预计不会看到选择语言下拉菜单。不过,无论我设置了html lang属性还是我设置了浏览器首选语言,我总能看到它。我也注意到,元数据google-translate-customization标签是否存在似乎没有什么区别,小部件总是在视图中。



如果用户浏览器未设置为英文,我希望网站只能进行翻译。



任何建议将不胜感激。



使用的代码: -


$ b

 < meta name =google-translate-customizationcontent =6bb255d109276506- b73cb06230e6b6c0-gbb2acb9bc95b4a11-12\" >< /元> 

正文: -

 < div id =google_translate_element>< / div> 
< script>
function googleTranslateElementInit(){
new google.translate.TranslateElement({pageLanguage:'en',layout:google.translate.TranslateElement.FloatPosition.TOP_LEFT},'google_translate_element');
}
< / script>
< script src =// translate.google.com/translate_a/element.js?cb=googleTranslateElementInit\"> ;</script>


解决方案

你可以试试这个小小的jquery脚本:

  var userLang = navigator.language || navigator.userLanguage; 
if(userLang ==en){
$(#google_translate_element)。css([display,none]);
}

不知道 if m使用荷兰语浏览器,它显示nl为userLang。我很确定这个英文名字应该是en。否则,您必须提醒userlang并将其更改为。

  alert(userLang); 

继承人jsfiddle: http://jsfiddle.net/u950mwom/1/


Having opted for the "Automatic" version of Google Translate Widget, I expected not to see the "Select Language" dropdown if my browser was the same language as the site. However, I see it all the time no matter what I set the html lang attribute to or what I set my browsers preferred language to. I have also noticed that it doesn't seem to make any difference whether the meta "google-translate-customization" tag is there or not, the widget is always in view.

I'd like the site to just be translated if the users browser isn't set to English.

Any advice would be appreciated.

Code used:-

In head:-

<meta name="google-translate-customization" content="6bb255d109276506-b73cb06230e6b6c0-gbb2acb9bc95b4a11-12"></meta>

In Body:-

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

解决方案

You can try this small jquery script:

var userLang = navigator.language || navigator.userLanguage; 
if(userLang == "en"){
    $("#google_translate_element").css(["display", "none"]);
}

Not sure if the if is right I'm using a dutch browser and it showed nl as userLang. I'm pretty sure the english one should be named en. Otherwise you have to alert userlang and change it to that.

alert(userLang);

Heres the jsfiddle: http://jsfiddle.net/u950mwom/1/

这篇关于谷歌翻译不隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆