# express-simple-locale

> A simple Express middleware to guess the short-locale of a user.

Latest version **1.0.0** (published 2022-07-11) · MIT license · 0 weekly downloads

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

## Install

```sh
npm install express-simple-locale
pnpm add express-simple-locale
yarn add express-simple-locale
bun add express-simple-locale
```

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-07-11 |
| First published | 2017-07-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/express-simple-locale) |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 14.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Hugo Giraudel |
| Maintainers | kittygiraudel |
| Keywords | express, middleware, locale, language, i18n |

## Links

- npm: https://www.npmjs.com/package/express-simple-locale
- Repository: https://github.com/n26/express-simple-locale
- Homepage: https://github.com/n26/express-simple-locale#readme
- Issues: https://github.com/n26/express-simple-locale/issues
- npm.io page: https://npm.io/package/express-simple-locale

## Dependencies (1)

- [lodash.get](https://npm.io/package/lodash.get.md) ^4.4.2

## 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

- 1.0.0 (latest) — 2022-07-11
- 0.3.4 — 2020-07-22
- 0.3.3 — 2019-06-19
- 0.3.2 — 2019-06-07
- 0.3.1 — 2019-01-02
- 0.3.0 — 2018-10-09
- 0.2.2 — 2018-04-27
- 0.2.1 — 2018-01-18
- 0.2.0 — 2017-07-27
- 0.1.0 — 2017-07-11

## README

> **Note**  
> This project has been deprecated and will not be receiving any updates anymore.  
> Please, consider using an alternative package.

# express-simple-locale

A simple Express middleware to guess the **short-locale** of a user. It then saves the found locale on the request for further usage.

It tries, in that order:

1. The `locale` query parameter.
2. The cookie specified by `cookieName` option.
3. The first entry of `accept-language` header.
4. The `acceptedLanguages` key from the request.
5. The `hostname.locale` nested key from the request.

When found, the locale is split on spaces, hyphens, commas, and underscores so only the first part gets returned (`en_GB` -> `en`).

## Install

```
npm i --save express-simple-locale
```

## Options

| Name             | Type             | Default      | Description                                    |
| ---------------- | ---------------- | ------------ | ---------------------------------------------- |
| key              | String           | `locale`     |  the key to save locale to on the request      |
| supportedLocales | String[]         | `[]`         |  available locales for the app                 |
| defaultLocale    | String           | `en`         |  locale to fallback to                         |
| cookieName       | String           | `locale`     | cookie to try getting the locale from          |
| queryParams      | String\|String[] | `['locale']` | the query parameter(s) to look the locale from |

## Example

```js
import locale from "express-simple-locale";

const localeMiddlewareOptions = {
  key: "userLocale",
  supportedLocales: ["en", "fr", "it", "es", "de"],
  defaultLocale: "en",
  cookieName: "c00ki3z",
  queryParams: ["locale", "lang"],
};

express()
  .use(locale(localeMiddlewareOptions))
  .use((request, response, next) => {
    // request.userLocale
  });
```

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