How to check browser language check javascript example

get/check browser language detection in javascript with examples.

Browser language in javascript

In javascript, the NavigatorLanguage class has properties for knowing the language of a browser or CLient UI.

There are two read-only properties to retrieve browser language details.

It is a property used to tell the language of the client browser.

This property is always useful to check below things.

  1. Delivering personalized regional information based on the user language preferences
  2. It is useful for the localization of your application

The possible values returned with this property are “en”, “en-US”…etc

console.log(navigator.language); // output en-U

It is a property to return a list of client browser preferred languages based on user preferred language that comes first in the order

console.log(navigator.languages); // ["en-US", "en"]

javascript Example

Below are different usage examples in various browsers.

  • Chrome - to get User preferred language of browser UI
console.log(window.navigator.language);
console.log(window.navigator.languages);

output is

en - US[("en-US", "en")];
  • Firefox - to get User preferred language of browser UI
console.log(window.navigator.language);
console.log(window.navigator.languages);

output is

en - US[("en-US", "en")];

Internet Explorer or IE - To get Browser Language In IE older browser versions less than 10 versions, It always returns “en-us”. In the latest versions, It returns “en-US”

console.log(window.navigator.userLanguage);
console.log(window.navigator.browserLanguage);
console.log(window.navigator.systemLanguage);

Output is

en - US;
en - US;
en - US;

Safari - to get User preferred language of browser UI In safari older browser versions are less than 10 versions, It always returns “en-us”. In the latest versions, It returns “en-US”.

console.log(window.navigator.language);
console.log(window.navigator.languages);

output is

en - US[("en-US", "en")];