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() {
|
2020-05-22 13:20:55 +00:00
|
|
|
if (this.auth)
|
|
|
|
this.$i18n.locale = this.auth.locale;
|
2019-10-31 11:43:04 +00:00
|
|
|
|
2020-05-22 13:20:55 +00:00
|
|
|
if (this.recipientId)
|
|
|
|
this.$i18n.locale = await this.getLocale(this.recipientId);
|
2019-10-31 11:43:04 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2020-05-22 13:20:55 +00:00
|
|
|
getLocale(recipientId) {
|
2019-10-31 11:43:04 +00:00
|
|
|
return db.findOne(`
|
2019-12-19 11:42:50 +00:00
|
|
|
SELECT IF(u.lang IS NOT NULL, u.lang, LOWER(ct.code)) lang
|
|
|
|
FROM client c
|
|
|
|
JOIN country ct ON ct.id = c.countryFk
|
|
|
|
JOIN account.user u ON u.id = c.id
|
2020-05-22 13:20:55 +00:00
|
|
|
WHERE c.id = ?`, [recipientId]).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
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2020-05-22 13:20:55 +00:00
|
|
|
props: ['auth', 'recipientId']
|
2019-10-31 11:43:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Vue.mixin(userLocale);
|