How to make an automatic translation of the page is dependent on browser language?

Code Google translate which gives a list of languages in which to translate the page
<div class="lan">
 <div id="google_translate_element"></div><script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'es', includedLanguages: 'bn,da,de,en,es,fr,lb,nl,no,pt,sv', layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element');
}

var userLang = navigator.language || navigator.userLanguage;
console.log(userLang);
</script><script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script><div class="lan">
 <div id="google_translate_element"></div><script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'es', includedLanguages: 'bn,da,de,en,es,fr,lb,nl,no,pt,sv', layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element');
}

var userLang = navigator.language || navigator.userLanguage;
console.log(userLang);
</script><script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>


So how to determine browser language
var userLang = navigator.language || navigator.userLanguage;

Tell me how to do automatic translation?
April 19th 20 at 12:26
1 answer
April 19th 20 at 12:28
using if or case

Find more questions by tags Google TranslateJavaScript