2019-10-31 11:43:04 +00:00
|
|
|
const Vue = require('vue');
|
|
|
|
const db = require('../database');
|
2019-11-21 08:33:08 +00:00
|
|
|
const config = require('../config');
|
|
|
|
const fallbackLocale = config.i18n.fallbackLocale;
|
2019-10-31 11:43:04 +00:00
|
|
|
const userLocale = {
|
|
|
|
async serverPrefetch() {
|
|
|
|
if (this.clientId)
|
|
|
|
this.locale = await this.getLocale(this.clientId);
|
|
|
|
|
|
|
|
if (this.locale)
|
|
|
|
this.$i18n.locale = this.locale;
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getLocale(clientId) {
|
|
|
|
return db.findOne(`
|
|
|
|
SELECT lang FROM account.user
|
|
|
|
WHERE id = ?`, [clientId]).then(rows => {
|
2019-11-21 08:33:08 +00:00
|
|
|
if (rows)
|
|
|
|
return rows.lang;
|
|
|
|
else return fallbackLocale;
|
2019-10-31 11:43:04 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
props: ['clientId']
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Vue.mixin(userLocale);
|