javascript - Node internationalisation not working inside Jade views (node i18n) -
i've been using i18n node module internationalisation. in root initialise module follows:
i18n.configure({ locales: ['en', 'nl'], register: global, directory: path.join(__dirname, 'locales'), defaultlocale: 'en', objectnotation: true }); app.use(i18n.init);
this module registers translation function (__()
) global. however, function doesn't work, decided pass down method available in controllers , views:
app.use((req, res, next) => { res.locals.user = req.session.user || null; res.locals.formatdate = (data) => data ? format(data, process.env.date_format) : null; res.locals.__ = res.__ = () => i18n.__.apply(req, arguments); req.setlocale('en') next(); });
it works fine in controllers. use req.__('string-to-translate')
, translates desired.
however, when try use exact same function in views rendered pug/jade, returns me undefined
.
any ideas i'm doing wrong?
Comments
Post a Comment