Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think the main problem here is that the browser settings don't actually affect the <code>navigator.language</code> property that is obtained via javascript. </p> <p>What they do affect is the HTTP 'Accept-Language' header, but it appears this value is not available through javascript at all. (Probably why @anddoutoi states he can't find a reference for it that doesn't involve server side.)</p> <p>I have coded a workaround: I've knocked up a google app engine script at <a href="http://ajaxhttpheaders.appspot.com" rel="noreferrer">http://ajaxhttpheaders.appspot.com</a> that will return you the HTTP request headers via JSONP.</p> <p>(Note: this is a hack only to be used if you do not have a back end available that can do this for you. In general you should not be making calls to third party hosted javascript files in your pages unless you have a very high level of trust in the host.)</p> <p>I intend to leave it there in perpetuity so feel free to use it in your code.</p> <p>Here's some example code (in jQuery) for how you might use it</p> <pre><code>$.ajax({ url: "http://ajaxhttpheaders.appspot.com", dataType: 'jsonp', success: function(headers) { language = headers['Accept-Language']; nowDoSomethingWithIt(language); } }); </code></pre> <p>Hope someone finds this useful.</p> <p>Edit: I have written a small jQuery plugin on github that wraps this functionality: <a href="https://github.com/dansingerman/jQuery-Browser-Language" rel="noreferrer">https://github.com/dansingerman/jQuery-Browser-Language</a></p> <p>Edit 2: As requested here is the code that is running on AppEngine (super trivial really):</p> <pre><code>class MainPage(webapp.RequestHandler): def get(self): headers = self.request.headers callback = self.request.get('callback') if callback: self.response.headers['Content-Type'] = 'application/javascript' self.response.out.write(callback + "(") self.response.out.write(headers) self.response.out.write(")") else: self.response.headers['Content-Type'] = 'text/plain' self.response.out.write("I need a callback=") application = webapp.WSGIApplication( [('/', MainPage)], debug=False) def main(): run_wsgi_app(application) if __name__ == "__main__": main() </code></pre> <p>Edit3: Have open sourced the app engine code here: <a href="https://github.com/dansingerman/app-engine-headers" rel="noreferrer">https://github.com/dansingerman/app-engine-headers</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload