浏览器语言检测 [英] Browser language detection
问题描述
我需要在Angular2应用中检测浏览器语言.基于这种语言,我需要发送带有本地化和变量ID的请求(到后端的REST API),需要翻译.之后,我收到了翻译后的变量的响应.
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.
因此应用程序的工作流程是检测浏览器语言,好吧例如是en-US
,之后我将向后端发送请求,以给我提供ID为1,2,3,4的变量的en-US的lang ,5.响应是{{id:1, var:pay}, {id:1, var:title}}
等.
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.
那么我该如何使用Angular2(使用Typescript开发)浏览器语言进行检测?
So how can I detect with Angular2 (developed with typescript) browser language?
推荐答案
var userLang = navigator.language || navigator.userLanguage;
这篇关于浏览器语言检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!