Skip to content

Commit

Permalink
fix: bump deps, added test for detectLocale (closes #26 per #27)
Browse files Browse the repository at this point in the history
  • Loading branch information
niftylettuce committed Feb 26, 2021
1 parent 7697279 commit 5e4121e
Show file tree
Hide file tree
Showing 4 changed files with 993 additions and 688 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ class I18N {

// expose shorthand API methods
this.api = {};
Object.keys(this.config.api).forEach((key) => {
for (const key of Object.keys(this.config.api)) {
this[this.config.api[key]] = this[key];
this.api[key] = this[key];
this.api[this.config.api[key]] = this[key];
});
}

// configure i18n
this.configure(this.config);
Expand Down
38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,38 @@
"shadowgate15 (https://github.com/shadowgate15)"
],
"dependencies": {
"@hapi/boom": "^9.1.0",
"@hapi/boom": "^9.1.1",
"boolean": "3.0.2",
"country-language": "^0.1.7",
"debug": "^4.2.0",
"debug": "^4.3.1",
"i18n": "^0.13.2",
"i18n-locales": "^0.0.4",
"lodash": "^4.17.20",
"lodash": "^4.17.21",
"multimatch": "^5.0.0",
"punycode": "^2.1.1",
"qs": "^6.9.4",
"qs": "^6.9.6",
"titleize": "^2.1.0",
"tlds": "^1.212.0"
"tlds": "^1.218.0"
},
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"ava": "^3.13.0",
"@commitlint/cli": "^12.0.0",
"@commitlint/config-conventional": "^12.0.0",
"ava": "^3.15.0",
"codecov": "^3.8.1",
"cross-env": "^7.0.2",
"eslint": "^7.13.0",
"eslint-config-xo-lass": "^1.0.4",
"fixpack": "^3.0.6",
"husky": "^4.3.0",
"koa": "^2.13.0",
"cross-env": "^7.0.3",
"eslint": "^7.20.0",
"eslint-config-xo-lass": "^1.0.5",
"fixpack": "^4.0.0",
"husky": "^5.1.1",
"koa": "^2.13.1",
"koa-generic-session": "^2.1.1",
"lint-staged": "^10.5.1",
"lint-staged": "^10.5.4",
"nyc": "^15.1.0",
"remark-cli": "^9.0.0",
"remark-preset-github": "^3.0.4",
"sinon": "^9.2.1",
"supertest": "^6.0.1",
"xo": "^0.34.2"
"remark-preset-github": "^4.0.1",
"sinon": "^9.2.4",
"supertest": "^6.1.3",
"xo": "^0.38.1"
},
"engines": {
"node": ">=8.3.0"
Expand Down
24 changes: 24 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,3 +644,27 @@ test('errors if route out of order', async (t) => {
const res = await request(app.listen()).get('/');
t.is(res.status, 500);
});

test('supports detectLocale function', async (t) => {
const app = new Koa();
const i18n = new I18N({
detectLocale: () => 'zh',
phrases,
directory
});

app.use(session());
app.use(i18n.middleware);
app.use(i18n.redirect);

app.use((ctx) => {
const { locale } = ctx;
ctx.body = { locale };
ctx.status = 200;
});

const res = await request(app.listen()).get('/');

t.is(res.status, 302);
t.is(res.header.location, '/zh');
});
Loading

0 comments on commit 5e4121e

Please sign in to comment.