How to Detect Browser Language with Javascript

Detecting the browser language is a good way to implement multi-lingual websites. Usually users choose their language through some "dropdown" (or country flags). But it would be best, if your application automatically detects the browser language, and renders content based on that.

Demo

Language detected in the current browser is

Use navigator.language to Detect Browser Language

// Current browser language
var language = window.navigator.language

Language Support

The language returned by navigator.language is a string as defined in RFC BCP-47.

In case you want to use Google Translate API, you can easily convert this to a ISO-639 string (Google Translate API supports languages conforming to ISO-639).

Browser Support

navigator.language will work good in all modern browsers including IE11+.