/ never-odd-or-even / back / node_modules / koa-locale /

[ICO]NameLast modifiedSizeDescription
[PARENTDIR]Parent Directory  -  
[   ]package.json2 years ago2.0K 
[   ]index.js8 years ago2.0K 
[TXT]README.md8 years ago2.0K 
[   ]LICENSE8 years ago1.1K 
README.md

koa-locale

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

NPM version Build status Test coverage License Dependency status

Installation

$ npm install koa-locale

Usage

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

Apache/2.4.38 (Debian) Server at www.karls.computer Port 80