Files
gancio/plugins/i18n.js

23 lines
564 B
JavaScript
Raw Normal View History

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-07-26 23:51:32 +02:00
import locales from '../locales'
2019-04-03 00:25:12 +02:00
Vue.use(VueI18n)
2019-07-24 21:26:56 +02:00
export default async ({ app, store }) => {
2019-04-03 00:25:12 +02:00
// Set i18n instance on app
// This way we can use it in middleware and pages asyncData/fetch
2019-07-24 21:26:56 +02:00
const user_locale = await app.$axios.$get('/settings/user_locale')
2019-07-26 23:51:32 +02:00
for(let lang in user_locale) {
if (locales[lang]) merge(locales[lang], user_locale[lang])
}
2019-04-03 00:25:12 +02:00
app.i18n = new VueI18n({
2019-06-25 01:05:38 +02:00
locale: store.state.locale,
fallbackLocale: 'it',
2019-07-26 23:51:32 +02:00
messages: locales
2019-04-03 00:25:12 +02:00
})
}