koa-locale

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

koa-locale

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

$ npm install koa-locale
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();
});
/?locale=en-US
zh-CN.koajs.com
Accept-Language: zh-CN,zh;q=0.5
Cookie: locale=zh-TW
http://koajs.com/en
http://koajs.com/
http://koajs.cn/
http://koajs.it/

MIT