# koa-locale

> Get locale variable from query, subdomain, the last domain, accept-languages or cookie for koa.

Latest version **1.3.0** (published 2017-04-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-locale
pnpm add koa-locale
yarn add koa-locale
bun add koa-locale
```

## 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.3.0 |
| Published | 2017-04-12 |
| First published | 2014-03-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Author | Fangdun Cai |
| Maintainers | fundon |
| Keywords | koa, locale, i18n, L10n, language, lang |

## Links

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

## Dependencies (1)

- [delegates](https://npm.io/package/delegates.md) 1.0.0

## 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.3.0 (latest) — 2017-04-12
- 1.2.0 — 2016-06-26
- 1.1.0 — 2016-05-20
- 1.0.0 — 2015-03-08
- 0.3.0 — 2014-12-16
- 0.1.1 — 2014-03-30
- 0.1.0 — 2014-03-30

## README

# koa-locale

> Get locale variable from query, subdomain, the last domain, accept-languages or cookie for koa.

[![NPM version][npm-img]][npm-url]
[![Build status][travis-img]][travis-url]
[![Test coverage][coveralls-img]][coveralls-url]
[![License][license-img]][license-url]
[![Dependency status][david-img]][david-url]

### Installation

```bash
$ npm install koa-locale
```

### Usage

```js
var app = require('koa')();
var locale = require('koa-locale');

// the locale key name defaults to `locale`
locale(app, 'language');

app.use(function *(next) {
  // query: '?language=en'
  this.body = this.getLocaleFromQuery();
});
```

### API

#### ctx.getLocaleFromQuery(), ctx.request.getLocaleFromQuery()

```
/?locale=en-US
```

#### ctx.getLocaleFromSubdomain(), ctx.request.getLocaleFromSubdomain()

```
zh-CN.koajs.com
```

#### ctx.getLocaleFromHeader(multi = false), ctx.request.getLocaleFromHeader(multi = false)

```
Accept-Language: zh-CN,zh;q=0.5
```

#### ctx.getLocaleFromCookie(), ctx.request.getLocaleFromCookie()

```
Cookie: locale=zh-TW
```

#### ctx.getLocaleFromUrl(options), ctx.request.getLocaleFromUrl(options)

```
http://koajs.com/en
```

```
options = { offset: 2 }

http://koajs.com/foo/bar/en
```

#### ctx.getLocaleFromTLD(), ctx.request.getLocaleFromTLD()

```
http://koajs.com/
http://koajs.cn/
http://koajs.it/
```

### License

  MIT

[npm-img]: https://img.shields.io/npm/v/koa-locale.svg?style=flat-square
[npm-url]: https://npmjs.org/package/koa-locale
[travis-img]: https://img.shields.io/travis/koa-modules/locale.svg?style=flat-square
[travis-url]: https://travis-ci.org/koa-modules/locale
[coveralls-img]: https://img.shields.io/coveralls/koa-modules/locale.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/koa-modules/locale?branch=master
[license-img]: https://img.shields.io/badge/license-MIT-green.svg?style=flat-square
[license-url]: LICENSE
[david-img]: https://img.shields.io/david/koa-modules/locale.svg?style=flat-square
[david-url]: https://david-dm.org/koa-modules/locale

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