Browser language detection [duplicate]

北战南征 提交于 2019-11-29 14:46:22

问题


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:


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


来源:https://stackoverflow.com/questions/36914151/browser-language-detection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!