localization - JavaScript for detecting browser language preference -
I am trying to detect the browser language preference using javascript.
If I use the browser language in IE in Devices & gt; Internet Options & gt; General & gt; Language
, How can I read this value using Javascript?
The only problem with Firefox is that I tools & gt; Options & gt; Content & gt; I'm not able to detect settings for
. navigator. Linguistics
by using languages
using navigator.userLanguage
, this start & gt; ControlPanel & gt; Regional Language Language Options & gt; Regional options detect settings made through the
tab.
I have tested with the navigator.browser language
and the Navigator systemLanguage
but the first setting ( Tools> InternetOptions & gt; General> Languages
)
I have found this that discusses it in detail, but the question is not unanswered: (
< / Div>
I think the main problem here is that the browser settings' t actually be navigator.language
Property javascript Receipt is done through the script.
What they affect is the HTTP 'Accept-language' header, but it seems that this value is not available through javascript exactly (probably why @Ddoutoi has said that he can not find a reference for this which does not include the server side.)
I have coded an alternate solution: I have dismissed a Google App Engine script, Which gives you the mean of HTTP JSONP Request header from.
(Note: This is used only for hacking if you have no back end available which can do this for you, normally you can use third-party Javascript should not host files, unless you trust the host.)
I always intend to leave it in the evening so that I can feel free to use it in my code.
Here are some example codes (in jQuery) that how you can use it
$. Ajax ({url: "http: // ajaxhttpheaders .appspot.com", data type: 'jsonp', success: function (header) {language = header ['accepted-language']; now do softing (language);} }); EDIT: I wrote a small jQuery plugin on the Gitubo which is to hide this functionality:
Edit 2: As requested here the code that is on AppEngine Running (really trivial):
class home page (webapp.RequestHandler): def mill (auto): header = self.request.headers callback = if callback: self.response Headers ['content-type'] = 'app / javascript' self.response.out.write (callback + "(") self.response.out if self.request.get ('callback'). .response.out.write (")"): Self-response.headers ['content-type'] = 'text / plain' self.response.out.write ("I need callback =") application = webapp.WSGIApplication ([( '/', Main page)], debug = false (): run_wsgi_app (application) if __name__ == "__main__": main ()
Edit 3: Open the app engine code here:
Comments
Post a Comment