Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 703
kamaci Avatar asked Aug 25 '11 13:08

kamaci


1 Answers

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.

like image 188
Beniamin Avatar answered Sep 28 '22 01:09

Beniamin