feat: gettext from app (#38)

```js
app.__(locale, text, value);
```
This commit is contained in:
fengmk2
2019-06-16 21:52:00 +08:00
committed by Yiyu He
parent 6d00106b63
commit 47162d3230
3 changed files with 71 additions and 20 deletions

View File

@@ -5,10 +5,9 @@ const koa = require('koa');
const request = require('supertest');
const pedding = require('pedding');
const mm = require('mm');
const locales = require('../');
const locales = require('..');
describe('koa-locales.test.js', function () {
afterEach(mm.restore);
describe('default options', function () {
@@ -122,6 +121,15 @@ describe('koa-locales.test.js', function () {
.expect(200, done);
});
it('should gettext work on app.__(locale, key, value)', function (done) {
request(app.callback())
.get('/app_locale_zh')
.expect({
email: '邮箱1',
})
.expect(200, done);
});
describe('query.locale', function () {
it('should use query locale: zh-CN', function (done) {
request(app.callback())
@@ -568,6 +576,13 @@ function createApp(options) {
const fname = options && options.functionName || '__';
app.use(function* () {
if (this.url === '/app_locale_zh') {
this.body = {
email: this.app[fname]('zh-cn', 'Email'),
};
return;
}
if (this.path === '/origin') {
assert(this.__getLocaleOrigin() === this.__getLocaleOrigin());
this.body = {