1

I'm currently working on translating a website navbar using google translate and I am detecting the user's browser preferences and am trying to use that information to translate the website accordingly.

var topNav = document.querySelector('#topnav');
var language = window.navigator.userLanguage || window.navigator.language;

function googleTranslateElementInit() {
    console.log(language);

    new google.translate.TranslateElement({
    pageLanguage: language,
     autoDisplay: false
    }, topNav);    
}

As of now using this code, the user still has to select a language from the dropdown menu provided by the google translate element but I am trying to bypass that and just translate my navbar right away after detecting the browser language preferences. Any ideas?

  • check this answer http://stackoverflow.com/a/32020889/4258817 - instead of hard-coding for English you can add a check of the `pageLanguage` and compare it with the user's language – Mousey Aug 15 '15 at 02:43

0 Answers0