# in-browser-language

> Get the language of the browser

Latest version **1.0.3** (published 2018-09-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install in-browser-language
pnpm add in-browser-language
yarn add in-browser-language
bun add in-browser-language
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2018-09-22 |
| First published | 2015-01-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Kevin Chapelier |
| Maintainers | kchapelier |
| Keywords | browser, language, detection |

## Links

- npm: https://www.npmjs.com/package/in-browser-language
- Repository: https://github.com/kchapelier/in-browser-language
- Issues: https://github.com/kchapelier/in-browser-language/issues
- npm.io page: https://npm.io/package/in-browser-language

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2018-09-22
- 1.0.2 — 2015-01-03
- 1.0.1 — 2015-01-02
- 1.0.0 — 2015-01-02

## README

# in-browser-language

This module is designed to be used with browserify or other CJS bundlers.

```npm i in-browser-language --save```

## How it works

The module checks for (in order) :

* `window.navigator.languages`
* `window.navigator.language`
* `window.clientInformation.userLanguage`
* `window.clientInformation.browserLanguage`
* `window.clientInformation.systemLanguage`

Some systems / browser may actually return the language of the OS instead of the language of the browser.

There is no way around this issue but it can be mitigated by allowing the user to change its language.

## Methods

**list()**

Return an array containing the languages.

**first()**

Return the first language of the list.

**pick(proposedLanguages, defaultLanguage)**

Pick the first language found both in the `proposedLanguages` array and the list of languages supported by the browser.

If there are no matches, the defaultLanguage is returned.

```js
var browserLanguage = require('in-browser-language');

console.log(browserLanguage.list());
// returns ['fr', 'en']

console.log(browserLanguage.first());
// returns 'fr'

console.log(browserLanguage.pick(['pl', 'ja', 'en', 'fr']));
// returns 'fr' as 'fr' is the first declared by the browser

console.log(browserLanguage.pick(['pl', 'ja'], 'pl'));
// returns 'pl' as there are no matches

console.log(browserLanguage.pick(['pl', 'ja']));
// returns null as there are no matches and no defaultLanguage
```

## History

### 1.0.3 (2018-09-18)

 * Remove `uniq` dependency.

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