salix/print/core/mixins/user-locale.js

25 lines
586 B
JavaScript

const Vue = require('vue');
const db = require('../database');
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 => {
return rows.lang;
});
}
},
props: ['clientId']
};
Vue.mixin(userLocale);