forked from dansingerman/jQuery-Browser-Language
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME
More file actions
19 lines (12 loc) · 1.1 KB
/
README
File metadata and controls
19 lines (12 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
This is a jQuery plugin to obtain the browser language setting
Note, the browser language can not (generally) be obtained via navigator.language (which is silly but there you go)
The browser language is available in "Accept-language" HTTP header, but this is not directly accessible via javascript.
The plugin utilises a service at http://ajaxhttpheaders.appspot.com which echos back the HTTP request headers in JSONP.
I made that as well, and intend to leave it running there in perpetuity (or as long as Google continue to host App Engine for free)
The Accept-Language header as defined by http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.10 uses an ISO 639-1 language code. The plugin converts this to an English Language description of the Language (e.g. 'Norwegian'), but also returns the complete value of the header if you need to do further processing.
Example usage:
<script>
$.browserLanguage(function( language , acceptHeader ){
alert("You have your browser language set to " + language + " and the complete value of the 'Accept-Language' header is " + acceptHeader);
})
</script>