jeresig / i18n-node-2

Lightweight simple translation module for node.js / express.js with dynamic json storage. Uses common __('...') syntax in app and templates.
MIT License
507 stars 79 forks source link

bind i18n in express #79

Closed crystalwm closed 8 years ago

crystalwm commented 8 years ago

when we bind i18n in express we can use __() method in our swig template.

why we could use __() methdod in our swig template ?

I have seen the i18n source code ,but I still can't figure these problem out?

crystalwm commented 8 years ago

在res对象上有一个locals属性,只要把方法写入到这个属性,就可以使用了。

app.use(function(req, res, next) {
    res.locals.time1=function(){
        return new Date();
    }
    next();
});

在swig模板中

<h1>{{ time1() }}</h1>