How can I get and parse Accept Header to get language at JavaScript?

不想你离开。 提交于 2019-12-22 05:22:06

问题


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) ?


回答1:


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.



来源:https://stackoverflow.com/questions/7191242/how-can-i-get-and-parse-accept-header-to-get-language-at-javascript

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