-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use async function and support egg@2 (#8)
- Loading branch information
1 parent
3ef32ac
commit 80e591d
Showing
11 changed files
with
62 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ module.exports = { | |
], | ||
devdep: [ | ||
'autod', | ||
'egg', | ||
'egg-bin', | ||
'egg-ci', | ||
'egg-mock', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
'use strict'; | ||
|
||
module.exports = () => { | ||
return function* i18n(next) { | ||
const ctx = this; | ||
return function i18n(ctx, next) { | ||
function gettext() { | ||
return ctx.__.apply(ctx, arguments); | ||
} | ||
this.locals = { | ||
ctx.locals = { | ||
gettext, | ||
__: gettext, | ||
}; | ||
|
||
yield next; | ||
return next(); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
'use strict'; | ||
|
||
module.exports = function*() { | ||
this.body = { | ||
message: this.__('Hello %s, how are you today? How was your %s.', 'fengmk2', 18), | ||
empty: this.__(), | ||
notexists_key: this.__('key not exists'), | ||
empty_string: this.__(''), | ||
novalue: this.__('key %s ok'), | ||
// __ 别名 gettext 也可以使用 | ||
arguments3: this.gettext('%s %s %s', 1, 2, 3), | ||
arguments4: this.gettext('%s %s %s %s', 1, 2, 3, 4), | ||
arguments5: this.__('%s %s %s %s %s', 1, 2, 3, 4, 5), | ||
arguments6: this.__('%s %s %s %s %s.', 1, 2, 3, 4, 5, 6), | ||
values: this.__('{0} {1} {0} {1} {2} {100}', [ 'foo', 'bar' ]), | ||
module.exports = async ctx => { | ||
ctx.body = { | ||
message: ctx.__('Hello %s, how are you today? How was your %s.', 'fengmk2', 18), | ||
empty: ctx.__(), | ||
notexists_key: ctx.__('key not exists'), | ||
empty_string: ctx.__(''), | ||
novalue: ctx.__('key %s ok'), | ||
arguments3: ctx.gettext('%s %s %s', 1, 2, 3), | ||
arguments4: ctx.gettext('%s %s %s %s', 1, 2, 3, 4), | ||
arguments5: ctx.__('%s %s %s %s %s', 1, 2, 3, 4, 5), | ||
arguments6: ctx.__('%s %s %s %s %s.', 1, 2, 3, 4, 5, 6), | ||
values: ctx.__('{0} {1} {0} {1} {2} {100}', [ 'foo', 'bar' ]), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters