Commit 3a59b54a authored by les's avatar les
Browse files

fix user_locale and favicon

parent f08273aa
......@@ -71,4 +71,7 @@ export default {
border-bottom: none;
}
#logo {
height: 30px;
}
</style>
import acceptLanguage from 'accept-language'
// import acceptLanguage from 'accept-language'
export default async function ({ req, app, store }) {
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')
app.i18n.locale = store.state.locale
}
}
// export default async function ({ req, app, store }) {
// // 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')
// // app.i18n.locale = store.state.locale
// // console.error('INSIDE MIDDLEWARE i18n settings locale ', lang)
// // }
// }
......@@ -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',
......
......@@ -26,14 +26,14 @@ const settingsController = {
}
})
// initialize user_locale
// // initialize user_locale
if (config.user_locale && fs.existsSync(path.resolve(config.user_locale))) {
const user_locale = fs.readdirSync(path.resolve(config.user_locale))
user_locale.forEach( async f => {
consola.info(`Loading user locale ${f}`)
const locale = path.basename(f, '.js')
settingsController.user_locale[locale] =
(await import(path.resolve(config.user_locale, f))).default
(await require(path.resolve(config.user_locale, f))).default
})
}
......
......@@ -132,6 +132,9 @@ export const mutations = {
},
setLocale (state, locale) {
state.locale = locale
},
setUserLocale (state, user_locale) {
state.user_locale = user_locale
}
}
......@@ -139,13 +142,11 @@ export const actions = {
// this method is called server side only for each request
// we use it to get configuration from db, setting locale, etc...
async nuxtServerInit ({ commit }, { app, store, req }) {
// TOFIX: check if we could retrieve it directly?
const settings = await app.$axios.$get('/settings')
commit('setSettings', settings)
// check if we could retrieve it directly?
const user_locale = await app.$axios.$get('/settings/user_locale')
if (user_locale[store.state.locale]) { store.commit('setUserLocale', user_locale[store.state.locale]) }
// apply settings
commit('showRecurrentEvents', settings.allow_recurrent_event && settings.recurrent_event_visible)
},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment