我如何获得并解析Accept Header以在JavaScript中获取语言? [英] How can I get and parse Accept Header to get language at JavaScript?
问题描述
如何在JavaScript中获取并解析Accept Header以获得两种字符=> en,tr,ar,fr等语言?
编辑:
navigator.language
或类似的东西,它给了我一种语言。不过,我在Firefox,Quick Locale中使用插件,它改变了本地。当我将其从英语更改为阿拉伯语时,仍然navigator.language说我正在使用英语。但是,当我连接到www.google.com时,在使用Quick Locale更改区域设置后,Google的主页将以阿拉伯语言打开。我想要像那样检测用户的语言。我会在检测到Google语言之后加载HTML文件的语言属性。
EDIT2:
有一个代码我的目的在这里:
接受标题脚本
然而,它会调用该URL: http ://ajaxhttpheaders.appspot.com
如何获取该网址的源代码?
我可以在服务器端编写类似于该代码的东西(通过REST与我的HTML端进行通信 - 这是我的最后一个解决方案)?
编辑:如果您想根据接受标题(如google)更改网站内容,则必须在服务器端进行。
How can I get and parse Accept Header to get language as two character => en, tr, ar, fr, etc. at JavaScript?
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.
EDIT2: There is a code for my purpose here: accept header script
However it makes a call to that URL: http://ajaxhttpheaders.appspot.com
How can I get the source code at that 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) ?
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.
这篇关于我如何获得并解析Accept Header以在JavaScript中获取语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!