如何获取和解析Accept Header以获取JavaScript语言?

时间:2021-10-29 01:53:59

How can I get and parse Accept Header to get language as two character => en, tr, ar, fr, etc. at JavaScript?

如何在JavaScript中获取并解析Accept Header以将语言作为两个字符=> en,tr,ar,fr等?

EDIT: When I use

编辑:当我使用

navigator.language

or something like that it gives me a language. However I am using a plug-in at Firefox, Quick Locale, it changes the local. When I change it from English to Arabic, still navigator.language says that I am using English. However when I connect to www.google.com, after I changed locale with Quick Locale, Google's homepage opens at Arabic language. I want to detect the user's language as like that. I will load the language properties of my HTML file after I detected the language as like Google.

或类似的东西它给了我一种语言。但是我在Firefox,Quick Locale上使用插件,它改变了本地。当我把它从英语改为阿拉伯语时,仍然navigator.language说我使用的是英语。但是,当我使用Quick Locale更改区域设置后,当我连接到www.google.com时,Google的主页将以阿拉伯语开启。我想像那样检测用户的语言。在我检测到像Google这样的语言后,我会加载HTML文件的语言属性。

EDIT2: There is a code for my purpose here: accept header script

EDIT2:这里有一个代码用于我的目的:接受标题脚本

However it makes a call to that URL: http://ajaxhttpheaders.appspot.com

但是它会调用该URL:http://ajaxhttpheaders.appspot.com

How can I get the source code at that URL?

如何获取该URL的源代码?

EDIT3: Can I write something similar to that code at my server side (to communicate my HTML side via REST - this is last solution for me) ?

EDIT3:我可以在服务器端编写类似于该代码的东西(通过REST与我的HTML端进行通信 - 这是我的最后一个解决方案)吗?

1 个解决方案

#1


3  

You can't. But you can try to detect browser language.

你不能。但您可以尝试检测浏览器语言。

Edit: If you would like to change site content depending on accept header (like google) then you have to do it on server side.

编辑:如果您想根据接受标题(如谷歌)更改网站内容,那么您必须在服务器端执行此操作。

#1


3  

You can't. But you can try to detect browser language.

你不能。但您可以尝试检测浏览器语言。

Edit: If you would like to change site content depending on accept header (like google) then you have to do it on server side.

编辑:如果您想根据接受标题(如谷歌)更改网站内容,那么您必须在服务器端执行此操作。