javascript - Access to i18n inside Socket.io -


i use i18n-2 internationalization this:

    router.get('/route', function (req, res, next) {       res.redirect('/route/?lang=' + req.i18n.getlocale());    }); 

right now, want access req.i18n inside socket.io block. use socket.io this:

    io.on('connection', function(client){          client.on('event', function(data){           ...         });     }); 

but here, don't access req use i18n. how can solve this?

if @ expressbind method of i18n-2, attach i18n property request object method proxies response object (to use in templates assume). can same thing client.

var i18n = require('i18n-2'); io.on('connection', function(client) {   client.i18n = new i18n(/* options */);   client.on('event', function(data) {     // use client.i18n.__   }); }); 

you fancier , use util.inherits give client same methods i18n has, prefer first way.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -