Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the browser language using JavaScript [duplicate]

Tags:

javascript

People also ask

How do I check my browser language?

Open the browser settings, and in the advanced section scroll down to find Languages . Open Language and Input Settings and add the language or language+region choice you want from the list available. Order the resulting list so that it is in descending order of preference.

How can I get browser language in PHP?

We can use HTTP_ACCEPT_LANGUAGE key to get the language of the browser. echo substr ( $_SERVER [ 'HTTP_ACCEPT_LANGUAGE' ], 0, 2); ?> You can test it by changing your browser's language.


Try this script to get your browser language

<script type="text/javascript">
var userLang = navigator.language || navigator.userLanguage; 
alert ("The language is: " + userLang);
</script>

Cheers


The "JavaScript" way:

var lang = navigator.language || navigator.userLanguage; //no ?s necessary

Really you should be doing language detection on the server, but if it's absolutely necessary to know/use via JavaScript, it can be gotten.