https://github.com/leighmcculloch/acceptedlanguages.js
A browser abstraction JavaScript library that tells you page and visitor language information like the accepted languages of the visitor and the current, alternate and relevant languages of the current page.
https://github.com/leighmcculloch/acceptedlanguages.js
Last synced: 20 days ago
JSON representation
A browser abstraction JavaScript library that tells you page and visitor language information like the accepted languages of the visitor and the current, alternate and relevant languages of the current page.
- Host: GitHub
- URL: https://github.com/leighmcculloch/acceptedlanguages.js
- Owner: leighmcculloch
- License: isc
- Created: 2015-06-25T05:52:59.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-07-07T16:30:57.000Z (almost 9 years ago)
- Last Synced: 2025-04-30T17:12:26.374Z (20 days ago)
- Language: JavaScript
- Homepage:
- Size: 74.2 KB
- Stars: 34
- Watchers: 4
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# acceptedlanguages.js
[](https://travis-ci.org/leighmcculloch/acceptedlanguages.js)
A simple JavaScript library that exposes the accepted languages of the visitor configured in their browser, and the languages relevant given the languages that the current page is alternatively available in.
## Install
### Bower
```bash
bower install acceptedlanguages
```### NPM
```bash
npm install acceptedlanguages --save
```### Manual
Download [acceptedlanguages.min.js](dist/acceptedlanguages.min.js).
## Usage
### Globals
Include `acceptedlanguages.js` into the page and call any of the global properties.
```html
console.log('Accepted: ' + window.acceptedlanguages.accepted);
console.log('Alternate: ' + window.acceptedlanguages.alternate);
console.log('Relevant: ' + window.acceptedlanguages.relevant);
```
If the browser is configured with the languages `pt, zh-Hans, en-US`, the above would output:
```text
Accepted: pt-BR,pt,zh-Hans,en-US
Alternate: pt-BR,es,en
Relevant: pt-BR,en
```### RequireJS
Include the library and then use as a dependency:
```javascript
define(['acceptedlanguages'], function(acceptedLanguages) {
console.log('Accepted: ' + acceptedlanguages.accepted);
console.log('Alternate: ' + acceptedlanguages.alternate);
console.log('Relevant: ' + acceptedlanguages.relevant);
});
```## Browser Compatibility
All browsers supporting ECMAScript 5: Chrome, Safari, Firefox, IE9, etc. If you need to support older browsers use [es5-shims](https://github.com/es-shims/es5-shim) to get the following:
* `Array.forEach`
* `Array.filter`
* `Array.map`Expect that Chrome and Firefox may return multiple languages while Safari and IE will return only a single language.