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?