# acceptedlanguages

> A simple JavaScript library that tells you 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.

Latest version **0.0.2** (published 2015-07-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install acceptedlanguages
pnpm add acceptedlanguages
yarn add acceptedlanguages
bun add acceptedlanguages
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2015-07-21 |
| First published | 2015-07-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 33 |
| Maintainers | leighmcculloch |

## Links

- npm: https://www.npmjs.com/package/acceptedlanguages
- Repository: https://github.com/leighmcculloch/acceptedlanguages.js
- Homepage: https://github.com/leighmcculloch/acceptedlanguages.js#readme
- Issues: https://github.com/leighmcculloch/acceptedlanguages.js/issues
- npm.io page: https://npm.io/package/acceptedlanguages

## Recent versions

- 0.0.2 (latest) — 2015-07-21

## README

# acceptedlanguages.js

[![Build Status](https://travis-ci.org/leighmcculloch/acceptedlanguages.js.svg?branch=master)](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 acceptedlangauges
```

### 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
<head>
  <link rel="alternate" hreflang="pt-BR" href="..." />
  <link rel="alternate" hreflang="es" href="..." />
  <link rel="alternate" hreflang="en" href="..." />
  <script src="acceptedlanguages.js"></script>
  <script type="text/javascript">
    console.log('Accepted:  ' + window.acceptedlanguages.accepted);
    console.log('Alternate: ' + window.acceptedlanguages.alternate);
    console.log('Relevant:  ' + window.acceptedlanguages.relevant);
  </script>
</head>
```

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.

---
_Source: https://npm.io/package/acceptedlanguages · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
