fix user_locale and favicon

This commit is contained in:
les
2019-09-19 16:23:46 +02:00
parent f08273aa10
commit 3a59b54a79
6 changed files with 38 additions and 21 deletions

View File

@@ -2,16 +2,28 @@ import Vue from 'vue'
import VueI18n from 'vue-i18n'
import merge from 'lodash/merge'
import locales from '../locales'
import acceptLanguage from 'accept-language'
Vue.use(VueI18n)
export default async ({ app, store }) => {
export default async ({ app, store, req }) => {
// Set i18n instance on app
for (const lang in store.state.user_locale) {
if (locales[lang]) { merge(locales[lang], user_locale[lang]) }
if (process.server) {
const acceptedLanguages = req.headers['accept-language']
const supportedLanguages = ['en', 'it', 'es']
acceptLanguage.languages(supportedLanguages)
const lang = acceptLanguage.get(acceptedLanguages)
store.commit('setLocale', lang || 'it')
const user_locale = await app.$axios.$get('/settings/user_locale')
if (user_locale[store.state.locale]) { store.commit('setUserLocale', user_locale[store.state.locale]) }
}
if (store.state.user_locale) {
merge(locales[store.state.locale], store.state.user_locale)
}
// Set i18n instance on app
app.i18n = new VueI18n({
locale: store.state.locale,
fallbackLocale: 'it',