code42day-i18n
Stack of connect middleware for language/locale detection and translation.
- detectLanguage - parse and detect browser language preference
- overwriteLanguage - overwrite language selection with query param and/or cookie
- gettext - insert simple gettext implementation in response
Also exposes parseAcceptLanguage - in case if you need parsed form
of Accept-Language
header for some other reason than language selection.
If you don't need this exact stack all of its components can be used separately.
Install
$ npm install --save code42day-i18n
Usage
var app = require('express');
var locale = {
supportedLanguages: ['de', 'fr', 'pl', 'en-GB', 'en-US'],
defaultLanguage: 'en',
gettextAlias: '_'
};
var i18n = require('code42day-i18n');
app.use(i18n.overwriteLanguage(locale));
app.use(i18n.detectLanguage(locale));
app.use(i18n.gettext)(locale));
License
MIT © code42day