2019-04-03 00:25:12 +02:00
|
|
|
import Vue from 'vue'
|
|
|
|
import VueI18n from 'vue-i18n'
|
2019-07-24 21:26:56 +02:00
|
|
|
import merge from 'lodash/merge'
|
2019-04-03 00:25:12 +02:00
|
|
|
|
|
|
|
Vue.use(VueI18n)
|
|
|
|
|
2021-11-09 12:46:46 +01:00
|
|
|
export default async ({ app, store, req }) => {
|
|
|
|
const messages = {}
|
2019-09-19 16:23:46 +02:00
|
|
|
if (process.server) {
|
2021-11-09 12:46:46 +01:00
|
|
|
store.commit('setLocale', req.acceptedLocale)
|
|
|
|
if (req.user_locale) {
|
|
|
|
store.commit('setUserLocale', req.user_locale)
|
|
|
|
}
|
2019-09-19 16:23:46 +02:00
|
|
|
}
|
|
|
|
|
2021-11-09 12:46:46 +01:00
|
|
|
messages[store.state.locale] = await import(/* webpackChunkName: "lang-[request]" */`../locales/${store.state.locale}.json`)
|
2020-02-20 18:37:10 +01:00
|
|
|
|
|
|
|
// always include en fallback locale
|
|
|
|
if (store.state.locale !== 'en') {
|
2021-11-09 12:46:46 +01:00
|
|
|
messages.en = await import('../locales/en.json')
|
2020-02-20 18:37:10 +01:00
|
|
|
}
|
|
|
|
|
2019-09-19 16:23:46 +02:00
|
|
|
if (store.state.user_locale) {
|
2019-10-11 18:34:14 +02:00
|
|
|
merge(messages[store.state.locale], store.state.user_locale)
|
2019-07-26 23:51:32 +02:00
|
|
|
}
|
|
|
|
|
2019-09-19 16:23:46 +02:00
|
|
|
// Set i18n instance on app
|
2019-04-03 00:25:12 +02:00
|
|
|
app.i18n = new VueI18n({
|
2019-06-25 01:05:38 +02:00
|
|
|
locale: store.state.locale,
|
2019-10-11 18:34:14 +02:00
|
|
|
fallbackLocale: 'en',
|
|
|
|
messages
|
2019-04-03 00:25:12 +02:00
|
|
|
})
|
|
|
|
}
|