Merge branch 'dev'
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,6 +4,7 @@
|
|||||||
config/development.json
|
config/development.json
|
||||||
gancio_config.json
|
gancio_config.json
|
||||||
config.json
|
config.json
|
||||||
|
db.sqlite
|
||||||
|
|
||||||
### Node template
|
### Node template
|
||||||
# Logs
|
# Logs
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
@@ -71,4 +71,7 @@ export default {
|
|||||||
border-bottom: none;
|
border-bottom: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#logo {
|
||||||
|
height: 30px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
import acceptLanguage from 'accept-language'
|
// import acceptLanguage from 'accept-language'
|
||||||
|
|
||||||
export default async function ({ req, app, store }) {
|
// export default async function ({ req, app, store }) {
|
||||||
if (process.server) {
|
// // if (process.server) {
|
||||||
const acceptedLanguages = req.headers['accept-language']
|
// // const acceptedLanguages = req.headers['accept-language']
|
||||||
const supportedLanguages = ['en', 'it', 'es']
|
// // const supportedLanguages = ['en', 'it', 'es']
|
||||||
acceptLanguage.languages(supportedLanguages)
|
// // acceptLanguage.languages(supportedLanguages)
|
||||||
const lang = acceptLanguage.get(acceptedLanguages)
|
// // const lang = acceptLanguage.get(acceptedLanguages)
|
||||||
store.commit('setLocale', lang || 'it')
|
// // store.commit('setLocale', lang || 'it')
|
||||||
app.i18n.locale = store.state.locale
|
// // 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 VueI18n from 'vue-i18n'
|
||||||
import merge from 'lodash/merge'
|
import merge from 'lodash/merge'
|
||||||
import locales from '../locales'
|
import locales from '../locales'
|
||||||
|
import acceptLanguage from 'accept-language'
|
||||||
|
|
||||||
Vue.use(VueI18n)
|
Vue.use(VueI18n)
|
||||||
|
|
||||||
export default async ({ app, store }) => {
|
export default async ({ app, store, req }) => {
|
||||||
|
|
||||||
// Set i18n instance on app
|
if (process.server) {
|
||||||
for (const lang in store.state.user_locale) {
|
const acceptedLanguages = req.headers['accept-language']
|
||||||
if (locales[lang]) { merge(locales[lang], user_locale[lang]) }
|
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({
|
app.i18n = new VueI18n({
|
||||||
locale: store.state.locale,
|
locale: store.state.locale,
|
||||||
fallbackLocale: 'it',
|
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))) {
|
if (config.user_locale && fs.existsSync(path.resolve(config.user_locale))) {
|
||||||
const user_locale = fs.readdirSync(path.resolve(config.user_locale))
|
const user_locale = fs.readdirSync(path.resolve(config.user_locale))
|
||||||
user_locale.forEach( async f => {
|
user_locale.forEach( async f => {
|
||||||
consola.info(`Loading user locale ${f}`)
|
consola.info(`Loading user locale ${f}`)
|
||||||
const locale = path.basename(f, '.js')
|
const locale = path.basename(f, '.js')
|
||||||
settingsController.user_locale[locale] =
|
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) {
|
setLocale (state, locale) {
|
||||||
state.locale = 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
|
// this method is called server side only for each request
|
||||||
// we use it to get configuration from db, setting locale, etc...
|
// we use it to get configuration from db, setting locale, etc...
|
||||||
async nuxtServerInit ({ commit }, { app, store, req }) {
|
async nuxtServerInit ({ commit }, { app, store, req }) {
|
||||||
|
|
||||||
|
// TOFIX: check if we could retrieve it directly?
|
||||||
const settings = await app.$axios.$get('/settings')
|
const settings = await app.$axios.$get('/settings')
|
||||||
commit('setSettings', 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
|
// apply settings
|
||||||
commit('showRecurrentEvents', settings.allow_recurrent_event && settings.recurrent_event_visible)
|
commit('showRecurrentEvents', settings.allow_recurrent_event && settings.recurrent_event_visible)
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user