gancio-upstream/middleware/i18n.js

12 lines
419 B
JavaScript
Raw Normal View History

2019-07-24 21:26:56 +02:00
import acceptLanguage from 'accept-language'
2019-07-23 01:33:13 +02:00
export default function ({ req, app, store }) {
if (process.server) {
2019-07-24 21:26:56 +02:00
const acceptedLanguages = req.headers['accept-language']
const supportedLanguages = ['en', 'it']
acceptLanguage.languages(supportedLanguages)
const lang = acceptLanguage.get(acceptedLanguages)
2019-07-23 01:33:13 +02:00
store.commit('setLocale', lang || 'it')
app.i18n.locale = store.state.locale
}
}