Google Translate isn't Hidden

梦想与她 提交于 2019-11-29 10:49:47

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/

Finally a fix for this (which is a long-standing bug in google). The code below hides the language selection drop-down box for English users on an English page. It copdes with locales like en-US also and newer browsers.

<div id="google_translate_element"></div>
<script type="text/javascript">
var userLang = navigator.language || navigator.userLanguage || navigator.languages; 
if (userLang.substr(0,2) != "en"){
  function googleTranslateElementInit() {
    new google.translate.TranslateElement({pageLanguage: 'en', layout: 
    google.translate.TranslateElement.FloatPosition.TOP_LEFT}, 'google_translate_element');
   }
 }
else { 
  document.getElementById("google_translate_element").style.display="none";
  }
</script>
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

cross-browser compatibility explained

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!