# fluent-langneg

> Language Negotiation API for Fluent

Latest version **0.3.0** (published 2019-07-25) · Apache-2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install fluent-langneg
pnpm add fluent-langneg
yarn add fluent-langneg
bun add fluent-langneg
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2019-07-25 |
| First published | 2017-02-27 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | separate (@types/fluent-langneg) |
| Module format | ESM + CommonJS |
| Node | >=8.9.0 |
| Dependencies | 0 |
| Unpacked size | 57.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1007 |
| Author | Mozilla |
| Maintainers | mozpike, stasm, zbraniecki |
| Keywords | localization, l10n, internationalization, i18n, locale, language, language-negotiation |

## Links

- npm: https://www.npmjs.com/package/fluent-langneg
- Repository: https://github.com/projectfluent/fluent.js
- Homepage: https://projectfluent.org
- Issues: https://github.com/projectfluent/fluent.js/issues
- npm.io page: https://npm.io/package/fluent-langneg

## Alternatives

- [messageformat](https://npm.io/package/messageformat.md) — 329.7K weekly downloads
- [@mintlify/scraping](https://npm.io/package/@mintlify/scraping.md) — 294.8K weekly downloads
- [@mintlify/previewing](https://npm.io/package/@mintlify/previewing.md) — 209.5K weekly downloads
- [@mintlify/prebuild](https://npm.io/package/@mintlify/prebuild.md) — 209.5K weekly downloads
- [@mintlify/link-rot](https://npm.io/package/@mintlify/link-rot.md) — 206.3K weekly downloads

## Recent versions

- 0.3.0 (latest) — 2019-07-25
- 0.2.0 — 2019-07-01
- 0.1.1 — 2019-02-07
- 0.1.0 — 2017-08-17
- 0.0.3 — 2017-08-02
- 0.0.2 — 2017-04-20
- 0.0.1 — 2017-02-27

## README

# fluent-langneg

`fluent-langneg` is an API for negotiating languages. It's part of
Project Fluent, a localization framework designed to unleash 
the expressive power of the natural language.

It's main function is to provide functionality around the
[Intl.Locale][] API with a focus
on language negotiation, matching and selection.


## Installation

`fluent-langneg` can be used both on the client-side and the server-side.
You can install it from the npm registry or use it as a standalone script.

    npm install fluent-langneg


## How to use

```javascript
import { negotiateLanguages } from 'fluent-langneg';

const supportedLocales = negotiateLanguages(
  navigator.languages,       // requested locales
  ['de', 'en-US', 'pl'],     // available locales
  { defaultLocale: 'en-US' }
);
```

The API reference is available at
https://projectfluent.org/fluent.js/fluent-langneg.

## Strategies

The API supports three negotiation strategies:

### filtering (default)

In this strategy the algorithm will look for the best matching available
locale for each requested locale.

Example:

requested: ['de-DE', 'fr-FR']
available: ['it', 'de', 'en-US', 'fr-CA', 'de-DE', 'fr', 'de-AU']

supported: ['de-DE', 'fr']

### matching

In this strategy the algorithm will try to match as many available locales
as possible for each of the requested locale.

Example:

requested: ['de-DE', 'fr-FR']
available: ['it', 'de', 'en-US', 'fr-CA', 'de-DE', 'fr', 'de-AU']

supported: ['de-DE', 'de', 'fr', 'fr-CA']

### lookup

In this strategy the algorithm will try to find the single best locale
for the requested locale list among the available locales.

Example:

requested: ['de-DE', 'fr-FR']
available: ['it', 'de', 'en-US', 'fr-CA', 'de-DE', 'fr', 'de-AU']

supported: ['de-DE']

### API use:

```javascript
let supported = negotiateLanguages(requested, available, {
  strategy: 'matching',
});
```

## Likely subtags

Fluent Language Negotiation module carries its own minimal list of likely
subtags data, which is useful in finding most likely available locales
in case the requested locale is too generic.

An example of that scenario is when the user requests `en` locale, and
the application supportes `en-GB` and `en-US`.

## Learn more

Find out more about Project Fluent at [projectfluent.org][], including
documentation of the Fluent file format ([FTL][]), links to other packages and
implementations, and information about how to get involved.


[projectfluent.org]: https://projectfluent.org
[FTL]: https://projectfluent.org/fluent/guide/
[Intl.Locale]: https://github.com/tc39/proposal-intl-locale

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