Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Browser language detection [duplicate]

Tags:

I need in my Angular2 app detect browser language. Based on this language I need to send request (to a REST API of backend) with localization and IDs of my variables, which I need to translate. After that I received response with translated variables.

So the app workflow is to detect browser language, ok it is for example en-US, after that I am going to sent request to backend give me lang for en-US for variables with IDs 1,2,3,4,5. The response is {{id:1, var:pay}, {id:1, var:title}} etc.

So how can I detect with Angular2 (developed with typescript) browser language?

like image 493
Loutocký Avatar asked Apr 28 '16 12:04

Loutocký


People also ask

How do I check my browser language?

Open the browser settings, and in the advanced section scroll down to find Languages . Open Language and Input Settings and add the language or language+region choice you want from the list available. Order the resulting list so that it is in descending order of preference. You don't need to restart Chrome.

How do I know what language a user is?

In this article, we'll go through three different ways of detecting a user's locale: through the browser's navigator. language s (on the client) object, through the Accept-Language HTTP header (on the server), and through geolocation using the user's IP address (on the server).

Which code can be used to find out the browser language via console in dev tools?

By using JavaScript, this task can be easily done by using: Languages property is available for the navigator interface, which returns the most preferred / user preferred language set in the web browser.

What is navigator language?

The Navigator language property is used for returning the browser's language version. It is a read-only property and it returns a string representing the language version of the browser.


1 Answers

var userLang = navigator.language || navigator.userLanguage; 

2021 Edit

Looks like userLanguage does not exist anymore (at least with Typescript lib).

And it's not on docs : just use navigator.language

MDN DOC

like image 158
Günter Zöchbauer Avatar answered Oct 17 '22 01:10

Günter Zöchbauer