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

Accept-Language is not used at all #15

Closed foobar321 closed 9 years ago

foobar321 commented 11 years ago

prefLocale variable seems to be unused. Or please give an example with ejs and language detection just based on accept-language header (no cookies and no subdomains).

aseemk commented 10 years ago

It'd be great to have an option to auto-use Accept-Language. For now, here's how you can do it:

// ...

    // Attach the i18n property to the express request object
    // And attach helper methods for use in templates
    I18n.expressBind(app, {
        // setup some locales - other locales default to en silently
        locales: ['en', 'de']
    });

    app.use(function (req, res, next) {
        req.i18n.setLocale(req.i18n.preferredLocale(req));
        next();
    });

// ...
gjuchault commented 9 years ago

req.i18n.setLocale(req.i18n.preferredLocale(req));

That is actually the way it's meant to use...