Skip to content

Commit

Permalink
fixed register methods for express3 see: jeresig#5
Browse files Browse the repository at this point in the history
  • Loading branch information
andineck committed Feb 20, 2013
1 parent fcac0d6 commit 26701f6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ i18n.expressBind = function(app, opt) {

// Express 3
if (res.locals) {
i18n.registerMethods(res.locals)
i18n.registerMethods(res.locals, req);
}

next();
Expand All @@ -90,11 +90,15 @@ i18n.expressBind = function(app, opt) {
}
};

i18n.registerMethods = function(helpers) {
i18n.registerMethods = function(helpers, req) {
i18n.resMethods.forEach(function(method) {
helpers[method] = function(req) {
return req.i18n[method].bind(req.i18n);
};
if (req) {
helpers[method] = req.i18n[method].bind(req.i18n);
} else {
helpers[method] = function(req) {
return req.i18n[method].bind(req.i18n);
};
}
});

return helpers;
Expand Down

0 comments on commit 26701f6

Please sign in to comment.