(refactor) reference config from prototype instead of importing it

This commit is contained in:
Valentyne Stigloher 2024-01-26 14:41:24 +01:00
parent 17ee6de8c3
commit 13cbc104e0

View File

@ -1,6 +1,5 @@
import Vue from 'vue'; import Vue from 'vue';
import { Translator } from '../src/translator.js'; import { Translator } from '../src/translator.js';
import config from '../data/config.suml';
import { buildDict } from '../src/helpers.js'; import { buildDict } from '../src/helpers.js';
import { DateTime, Settings } from 'luxon'; import { DateTime, Settings } from 'luxon';
import { decodeTime } from 'ulid'; import { decodeTime } from 'ulid';
@ -13,7 +12,7 @@ export default ({ app, store }) => {
Vue.prototype.$base = process.env.BASE_URL; Vue.prototype.$base = process.env.BASE_URL;
const translator = new Translator(translations, baseTranslations, config); const translator = new Translator(translations, baseTranslations, app.$config);
Vue.prototype.$translator = translator; Vue.prototype.$translator = translator;
Vue.prototype.$t = (key, params = {}, warn = false) => translator.translate(key, params, warn); Vue.prototype.$t = (key, params = {}, warn = false) => translator.translate(key, params, warn);
Vue.prototype.$te = (key, fallback = false) => { Vue.prototype.$te = (key, fallback = false) => {
@ -34,12 +33,12 @@ export default ({ app, store }) => {
}; };
Vue.prototype.$locales = buildDict(function* () { Vue.prototype.$locales = buildDict(function* () {
if (config.locale !== '_') { if (app.$config.locale !== '_') {
yield [config.locale, process.env.LOCALES[config.locale]]; yield [app.$config.locale, process.env.LOCALES[app.$config.locale]];
} }
for (const l in process.env.LOCALES) { for (const [locale, localeDescription] in Object.entries(process.env.LOCALES)) {
if (process.env.LOCALES.hasOwnProperty(l) && l !== config.locale) { if (locale !== app.$config.locale) {
yield [l, process.env.LOCALES[l]]; yield [locale, localeDescription];
} }
} }
}); });
@ -74,7 +73,7 @@ export default ({ app, store }) => {
}; };
try { try {
Settings.defaultLocale = config.intlLocale || config.locale; Settings.defaultLocale = app.$config.intlLocale || app.$config.locale;
DateTime.now().toFormat('y-MM-dd HH:mm'); // test if locale is supported by luxon DateTime.now().toFormat('y-MM-dd HH:mm'); // test if locale is supported by luxon
} catch { } catch {
Settings.defaultLocale = 'en'; Settings.defaultLocale = 'en';