Skip to content

Gets browser's language setting in a useful way. Based on https://github.com/dansingerman/jQuery-Browser-Language but changed to use my own URL to check languages.

Notifications You must be signed in to change notification settings

brenes/jQuery-Browser-Language

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

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 makes an ajax request to an url provided by us which must return a json hash with the content of the Accept-Language header. An example would be

    {
        Accept-Language: "es,en;q=0.8,fr;q=0.6"
    }

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(my-checking-url, function( languages , acceptHeader ){
      console.log("You lke these languages " + languages.join(",") + " and the complete value of the 'Accept-Language' header is " + acceptHeader);
    })
</script>

About

Gets browser's language setting in a useful way. Based on https://github.com/dansingerman/jQuery-Browser-Language but changed to use my own URL to check languages.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%