Languages
[Edit]
EN

JavaScript - detect languages used by user

0 points
Created by:
Romany-Welsh
382

In this article, we'll show you how to detect browser language preference with JavaScript.

Using JavaScript you can get information about the languages ​​that are most used by the user's browser.

navigator.languages property
navigator.languages property

1. navigator.languages property

navigator.languages property returns an array of preferred languages.

// ONLINE-RUNNER:browser;
const languages = navigator.languages;
console.log(  languages   );

Note:

The language codes are defined by ISO 639-1: 2002.

2. navigator.language property

To get only the first, most frequently used language you can use the navigator.language property.

// ONLINE-RUNNER:browser;
const language = navigator.language;
console.log(  language   );

 

References

  1. ISO 639-1 - Wikipedia
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join