Skip to content

Instantly share code, notes, and snippets.

@jkantr
Last active July 12, 2017 17:42
Show Gist options
  • Save jkantr/14d52ecee3abd7dc00b2d45de7583d03 to your computer and use it in GitHub Desktop.
Save jkantr/14d52ecee3abd7dc00b2d45de7583d03 to your computer and use it in GitHub Desktop.
import requestLanguage from 'express-request-language';
import models, { Locale, User, UrlManager } from './data/models';
app.use(async (res, req, next) => {
const locales = await Locale.findAll({}).then(locales => locales.map(loc => loc.locale));
//app.set('locales', locales);
req.locales = locales;
next();
});
app.use((req, res, next) => {
return requestLanguage({
languages: req.locales, // unable to get array
queryName: 'lang',
cookie: {
name: 'lang',
options: {
path: '/',
maxAge: 3650 * 24 * 3600 * 1000, // 10 years in miliseconds
},
url: '/lang/{language}',
},
})(req, res, next);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment