How to Detect Browser Language with Javascript

javascript
Published on September 27, 2017

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+.

In this Tutorial