S
S
Sergey2020-04-17 02:57:00
JavaScript
Sergey, 2020-04-17 02:57:00

How to make automatic page translation depending on the browser language?

There is such a Google translate code that gives a list of languages ​​into 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>


And there is such a way to determine the language of the browser
var userLang = navigator.language || navigator.userLanguage;

Can you tell me how to do automatic translation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2020-04-17
@dimonchik2013

via if or case

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question