connect-gettext
Lightweight implementation of gettext as connect middleware.
Install
$ npm install --save connect-gettext
Usage
Use with any middleware that sets req.lang
- such as detect-language and/or overwrite-language.
var app = require('express');
var locale = {
supportedLanguages: ['de', 'fr', 'pl', 'en-GB', 'en-US'],
defaultLanguage: 'en',
gettextAlias: '_'
};
// use any middleware that sets req.lang
// `detect-language` is just an example
app.use(require('detect-language')(locale));
app.use(require('connect-gettext')(locale));
Once the middleware is applied res.locals.gettext
will have gettext
implementation inserted
and res.render
will be able to use it when rendering pages.
p
| #{_("This is how you can use it")}
span= _("with Jade")
License
MIT © Damian Krzeminski