Last active
July 12, 2017 17:42
-
-
Save jkantr/14d52ecee3abd7dc00b2d45de7583d03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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