Languages
[Edit]
EN

JavaScript - detect languages used by user

3 points
Created by:
Welsh
902

In this article, we'll show you how to detect user language preferences using JavaScript.

Browser API provides information about the languages ​​that are mostly used by the user.

navigator.languages property example
navigator.languages property example

1. navigator.languages property

navigator.languages property returns languages ordered by usage (starting from mostly used).

// ONLINE-RUNNER:browser;

const languages = navigator.languages;

console.log(languages);

Note: returned language codes uses ISO 639-1: 2002.

2. navigator.language property

To get only one most frequently used language you can use navigator.language property.

// ONLINE-RUNNER:browser;

const language = navigator.language;

console.log(language);

 

References

  1. ISO 639-1 - Wikipedia
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
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