Skip to content

Commit

Permalink
i18n support
Browse files Browse the repository at this point in the history
  • Loading branch information
openhoat committed Dec 14, 2015
1 parent 94c9718 commit ca165a2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions lib/hw-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,13 @@ that = {
data = {code: errorCode, message: 'internal error'};
}
if (data.message) {
if (req && req.t) { // i18next handler
data.message = req.t(data.message, _.extend({lng: req.lng}, reqParams));
} else if (res && res.__) { // i18n handler
data.message = req.__(data.message);
try {
if (req && typeof req.t === 'function') { // i18next handler
data.message = req.t(data.message, _.extend({lng: req.lng}, reqParams));
} else if (res && typeof res.__ === 'function') { // i18n handler
data.message = res.__(data.message);
}
} catch (err) {
}
}
if (logger.enabledLevels.debug) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hw-error",
"version": "0.1.9",
"version": "0.1.10",
"description": "Better error management",
"main": "lib/hw-error.js",
"author": "Olivier Penhoat <openhoat@gmail.com> (http://headwood.net/)",
Expand Down

0 comments on commit ca165a2

Please sign in to comment.