Skip to content

Commit

Permalink
Bump v2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Apr 12, 2017
1 parent de84043 commit f88c9ba
Show file tree
Hide file tree
Showing 7 changed files with 1,164 additions and 31 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.node-version
node_modules/
.DS_Store
*.swp
node_modules
coverage
.nyc_output
*.log
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sudo: false
language: node_js
node_js:
- "node"
- "7"
script: "npm run test-travis"
after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ LOCALE_METHODS.forEach((m) => {
Object.defineProperty(I18n.prototype, SET_PREFIX + m, {
value: function () {
let locale = getLocale(this.request[GET_PREFIX + m]())
if (locale === this.getLocale().toLowerCase()) return true
if (locale === this.getLocale()) return true
if ((locale = filter(locale, this.locales))) {
this.setLocale(locale)
debug('Overriding locale from %s : %s', m.toLowerCase(), locale)
Expand Down Expand Up @@ -81,8 +81,9 @@ function ial(app, opts) {
return this._i18n
}

const i18n = this._i18n = new I18n(opts)
const i18n = new I18n(opts)
i18n.request = this.request
this._i18n = i18n

// merge into ctx.state
this.state.i18n = i18n
Expand Down
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "koa-i18n",
"version": "2.0.1",
"version": "2.1.0",
"description": "Lightweight simple translation middleware for koa, based on i18n-2",
"main": "index.js",
"scripts": {
"test": "mocha --require should --reporter spec --timeout 5000 test",
"test-cov": "istanbul cover node_modules/.bin/_mocha -- -R dot -t 5000 test/*.js",
"test-travis": "istanbul cover node_modules/.bin/_mocha --report lcovonly -- -R dot -t 5000 test/*.js"
},
"repository": "http://github.com/koa-modules/koa-i18n.git",
"repository": "koa-modules/koa-i18n",
"keywords": [
"koa",
"locale",
Expand All @@ -22,20 +22,20 @@
"i18n-2": "*"
},
"devDependencies": {
"istanbul": "0.4.x",
"jade": "*",
"koa": "next",
"koa-compose": "3.x",
"koa-convert": "1.x",
"koa-locale": "*",
"koa-swig": "2.*",
"koa-views": "*",
"mocha": "*",
"should": "*",
"supertest": "*"
"istanbul": "^0.4.5",
"koa": "^2.2.0",
"koa-compose": "^3.2.1",
"koa-convert": "^1.2.0",
"koa-locale": "^1.3.0",
"koa-swig": "^2.2.1",
"koa-views": "^6.0.1",
"mocha": "^3.2.0",
"pug": "^2.0.0-beta11",
"should": "^11.2.1",
"supertest": "^3.0.0"
},
"engines": {
"node": ">= 4.0.0"
"node": ">=7"
},
"files": [
"LICENSE",
Expand Down
File renamed without changes.
23 changes: 11 additions & 12 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const views = require('koa-views')
const i18n = require('..')

describe('koa-i18n', () => {

describe('Detect the Querystring', () => {
it('should be `en` locale', () => {
var app = new Koa()
Expand Down Expand Up @@ -186,7 +185,7 @@ describe('koa-i18n', () => {
})
})

describe('working together with koa-views, jade render', () => {
describe('working together with koa-views, pug render', () => {
it('should be render by zh-cn locale', () => {
var app = new Koa()

Expand All @@ -198,19 +197,19 @@ describe('koa-i18n', () => {
modes: ['cookie']
}))

app.use(convert(views(__dirname + '/fixtures/', {
default: 'jade'
})))

app.use(convert(function*(next) {
yield this.render('index')
app.use(views(__dirname + '/fixtures/', {
extension: 'pug'
}))

app.use(async (ctx, next) => {
await ctx.render('index')
})

return request(app.listen())
.get('/')
.set('Cookie', 'lang=zh-cn')
.expect(/<div><p>英文<\/p><\/div>/)
.expect(200)
.get('/')
.set('Cookie', 'lang=zh-cn')
.expect(/<div><p>英文<\/p><\/div>/)
.expect(200)
})
})

Expand Down
Loading

0 comments on commit f88c9ba

Please sign in to comment.