Is there anyway to detect OS language using javascript?

Viewed 30798

I need to detect OS language using javascript so I can view my page depending on the language.

I know that we can detect the browser language but that is not enough for me.

I need Operation System language

Thanks in advance

6 Answers

This returns the system language:

Intl.DateTimeFormat().resolvedOptions().locale

You can get from the js with default languages, and supported languages through this:

navigator.language

Return 'en-GB'

navigator.languages

Returns ['en-GB', 'en-US', 'en', 'zh-CN']

PS: I tested on Chrome on Windows (Not sure if Mac also works the same)

Related