Browser language detection [duplicate]

2020-02-26 10:03发布

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?

1条回答
Deceive 欺骗
2楼-- · 2020-02-26 10:48
var userLang = navigator.language || navigator.userLanguage; 
查看更多
登录 后发表回答