From 06f63c5eda54c4a89eba8edbf297b724d2453468 Mon Sep 17 00:00:00 2001 From: anwolosz Date: Tue, 24 Dec 2024 13:17:52 +0100 Subject: [PATCH 1/4] Dynamic load (all together) --- src/router/index.ts | 13 ++++++- src/stores/SynopsisStore.ts | 73 +++++++++++++++++++++++++++---------- 2 files changed, 65 insertions(+), 21 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index addcd0a6..7965e6b8 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -128,7 +128,18 @@ const router = createRouter({ }, }) -router.beforeEach((to, from, next) => { +router.beforeEach(async (to, from, next) => { + + let translations = [] + for (let i = 0; i< useSynopsisStore().synopses.length; i++) + { + translations.push(useSynopsisStore().synopses[i].translation) + } + if (to.params.translation && !translations.includes(to.params.translation as string)) + { + await useSynopsisStore().loadSynopsis((to.params.translation as string).toLowerCase()) + } + useSynopsisStore().loadSynopses() useSynopsisStore().setupLanguage(to.params.language) useSynopsisStore().setupTranslation(to.params.translation, options) diff --git a/src/stores/SynopsisStore.ts b/src/stores/SynopsisStore.ts index f89c28dd..854afaaa 100644 --- a/src/stores/SynopsisStore.ts +++ b/src/stores/SynopsisStore.ts @@ -9,16 +9,16 @@ import { fetchGospel, isValidDate} from '@/utils/calendarGospel'; import synopsisSZIT from '@/assets/translations/szit.json' -import synopsisKG from '@/assets/translations/kg.json' -import synopsisKNB from '@/assets/translations/knb.json' -import synopsisRUF from '@/assets/translations/ruf.json' +// import synopsisKG from '@/assets/translations/kg.json' +// import synopsisKNB from '@/assets/translations/knb.json' +// import synopsisRUF from '@/assets/translations/ruf.json' import synopsisESV from '@/assets/translations/esv.json' -import synopsisEU from '@/assets/translations/eu.json' -import synopsisBT from '@/assets/translations/bt.json' -import synopsisBJW from '@/assets/translations/bjw.json' -import synopsisRSP from '@/assets/translations/rsp.json' -import synopsisSBLGNT from '@/assets/translations/sblgnt.json' -import synopsisNV from '@/assets/translations/nv.json' +// import synopsisEU from '@/assets/translations/eu.json' +// import synopsisBT from '@/assets/translations/bt.json' +// import synopsisBJW from '@/assets/translations/bjw.json' +// import synopsisRSP from '@/assets/translations/rsp.json' +// import synopsisSBLGNT from '@/assets/translations/sblgnt.json' +// import synopsisNV from '@/assets/translations/nv.json' import dictionaryEn from '@/assets/languages/en.json' import dictionaryHu from '@/assets/languages/hu.json' import type { QuoteScheme } from '@/interfaces/dailyGospelInterface'; @@ -31,23 +31,23 @@ export const useSynopsisStore = defineStore('synopsis', { currentDictionary: dictionaryHu, currentLanguage: "hu", currentTranslation: "", - currentSynopsis: synopsisKG, + currentSynopsis: synopsisSZIT, dictionary: { hu: dictionaryHu as DictionaryScheme, en: dictionaryEn as DictionaryScheme }, synopses: [ synopsisSZIT as SynopsisScheme, - synopsisKG as SynopsisScheme, - synopsisKNB as SynopsisScheme, - synopsisRUF as SynopsisScheme, + // synopsisKG as SynopsisScheme, + // synopsisKNB as SynopsisScheme, + // synopsisRUF as SynopsisScheme, synopsisESV as SynopsisScheme, - synopsisEU as SynopsisScheme, - synopsisBT as SynopsisScheme, - synopsisBJW as SynopsisScheme, - synopsisRSP as SynopsisScheme, - synopsisSBLGNT as SynopsisScheme, - synopsisNV as SynopsisScheme + // synopsisEU as SynopsisScheme, + // synopsisBT as SynopsisScheme, + // synopsisBJW as SynopsisScheme, + // synopsisRSP as SynopsisScheme, + // synopsisSBLGNT as SynopsisScheme, + // synopsisNV as SynopsisScheme ], isLoading: false, dailyGospel: null as null | QuoteScheme, @@ -335,6 +335,39 @@ export const useSynopsisStore = defineStore('synopsis', { return false; } - } + }, + async loadSynopsis(translation : string) + { + const synopsis = (await import(`@/assets/translations/${translation}.json`)).default; + this.synopses.push(synopsis) + }, + async loadSynopses() { + if (this.synopses.length < 11) + { + const translationsToLoad = [ + 'kg', + 'knb', + 'ruf', + 'esv', + 'eu', + 'bt', + 'bjw', + 'rsp', + 'sblgnt', + 'nv', + ]; + + for (const path of translationsToLoad) { + try { + const translation = (await import(`@/assets/translations/${path}.json`)).default; + if (!this.synopses.includes(translation)) { + this.synopses.push(translation); + } + } catch (error) { + console.error(`Error loading translation from ${path}:`, error); + } + } + } + }, } }) \ No newline at end of file From 6797e35efdf7a2ddcc65f4eaa5ee3024c60fdb14 Mon Sep 17 00:00:00 2001 From: anwolosz Date: Sat, 18 Jan 2025 19:08:16 +0100 Subject: [PATCH 2/4] order of translations --- src/router/index.ts | 6 +----- src/stores/SynopsisStore.ts | 39 +++++++++++++++++++++---------------- src/utils/options.ts | 4 ++++ 3 files changed, 27 insertions(+), 22 deletions(-) create mode 100644 src/utils/options.ts diff --git a/src/router/index.ts b/src/router/index.ts index 7965e6b8..ea740a8b 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -9,11 +9,7 @@ import NotFoundView from '@/views/NotFoundView.vue' import Section from '@/components/Section.vue' import DailyGospelView from '@/components/DailyGospelView.vue' import { useSynopsisStore } from "@/stores/SynopsisStore" - -const options: { [key: string]: string[] } = { - "hu": ["SZIT", "KG", "KNB", "RUF"], - "en": ["ESV", "EU", "BT", "BJW", "RSP", "SBLGNT", "NV"] -} +import { options } from '@/utils/options' const languageDefaultRedirect = (path : string) => Object.keys(options).map(language => ({ diff --git a/src/stores/SynopsisStore.ts b/src/stores/SynopsisStore.ts index 854afaaa..de6f6525 100644 --- a/src/stores/SynopsisStore.ts +++ b/src/stores/SynopsisStore.ts @@ -23,7 +23,7 @@ import dictionaryEn from '@/assets/languages/en.json' import dictionaryHu from '@/assets/languages/hu.json' import type { QuoteScheme } from '@/interfaces/dailyGospelInterface'; import { ErrorCode } from '@/enums/ErrorCode'; - +import { options } from '@/utils/options'; export const useSynopsisStore = defineStore('synopsis', { state: () => { @@ -336,35 +336,40 @@ export const useSynopsisStore = defineStore('synopsis', { return false; } }, + getTranslationsList(){ + const translationsToLoad : string[] = Object.values(options) + .flat() + .map((value) => value); + return translationsToLoad + }, async loadSynopsis(translation : string) { const synopsis = (await import(`@/assets/translations/${translation}.json`)).default; this.synopses.push(synopsis) + const translations = this.getTranslationsList() + this.synopses.sort((a, b) => { + const indexA = translations.indexOf(a.translation); + const indexB = translations.indexOf(b.translation); + return (indexA === -1 ? Number.MAX_VALUE : indexA) - (indexB === -1 ? Number.MAX_VALUE : indexB); + }); }, async loadSynopses() { - if (this.synopses.length < 11) + const translationsToLoad = this.getTranslationsList() + if (this.synopses.length < translationsToLoad.length) { - const translationsToLoad = [ - 'kg', - 'knb', - 'ruf', - 'esv', - 'eu', - 'bt', - 'bjw', - 'rsp', - 'sblgnt', - 'nv', - ]; - for (const path of translationsToLoad) { try { - const translation = (await import(`@/assets/translations/${path}.json`)).default; + const translation = (await import(`@/assets/translations/${path.toLowerCase()}.json`)).default; if (!this.synopses.includes(translation)) { this.synopses.push(translation); + this.synopses.sort((a, b) => { + const indexA = translationsToLoad.indexOf(a.translation); + const indexB = translationsToLoad.indexOf(b.translation); + return (indexA === -1 ? Number.MAX_VALUE : indexA) - (indexB === -1 ? Number.MAX_VALUE : indexB); + }); } } catch (error) { - console.error(`Error loading translation from ${path}:`, error); + console.error(`Error loading translation from ${path.toLowerCase()}:`, error); } } } diff --git a/src/utils/options.ts b/src/utils/options.ts new file mode 100644 index 00000000..1ea4fdd8 --- /dev/null +++ b/src/utils/options.ts @@ -0,0 +1,4 @@ +export const options: { [key: string]: string[] } = { + "hu": ["SZIT", "KG", "KNB", "RUF"], + "en": ["ESV", "EU", "BT", "BJW", "RSP", "SBLGNT", "NV"] + } \ No newline at end of file From 50f478d493058ecfd4c759ed5f2b45b820d3512d Mon Sep 17 00:00:00 2001 From: anwolosz Date: Sun, 19 Jan 2025 00:13:20 +0100 Subject: [PATCH 3/4] sortTranslaions --- src/stores/SynopsisStore.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/stores/SynopsisStore.ts b/src/stores/SynopsisStore.ts index de6f6525..3f74a9a4 100644 --- a/src/stores/SynopsisStore.ts +++ b/src/stores/SynopsisStore.ts @@ -342,10 +342,7 @@ export const useSynopsisStore = defineStore('synopsis', { .map((value) => value); return translationsToLoad }, - async loadSynopsis(translation : string) - { - const synopsis = (await import(`@/assets/translations/${translation}.json`)).default; - this.synopses.push(synopsis) + sortTranslaions(){ const translations = this.getTranslationsList() this.synopses.sort((a, b) => { const indexA = translations.indexOf(a.translation); @@ -353,6 +350,12 @@ export const useSynopsisStore = defineStore('synopsis', { return (indexA === -1 ? Number.MAX_VALUE : indexA) - (indexB === -1 ? Number.MAX_VALUE : indexB); }); }, + async loadSynopsis(translation : string) + { + const synopsis = (await import(`@/assets/translations/${translation}.json`)).default; + this.synopses.push(synopsis) + this.sortTranslaions() + }, async loadSynopses() { const translationsToLoad = this.getTranslationsList() if (this.synopses.length < translationsToLoad.length) @@ -362,11 +365,7 @@ export const useSynopsisStore = defineStore('synopsis', { const translation = (await import(`@/assets/translations/${path.toLowerCase()}.json`)).default; if (!this.synopses.includes(translation)) { this.synopses.push(translation); - this.synopses.sort((a, b) => { - const indexA = translationsToLoad.indexOf(a.translation); - const indexB = translationsToLoad.indexOf(b.translation); - return (indexA === -1 ? Number.MAX_VALUE : indexA) - (indexB === -1 ? Number.MAX_VALUE : indexB); - }); + this.sortTranslaions() } } catch (error) { console.error(`Error loading translation from ${path.toLowerCase()}:`, error); From 6774dc2cbc456733bf1d705cea371e444dd2808e Mon Sep 17 00:00:00 2001 From: anwolosz Date: Sun, 19 Jan 2025 00:17:39 +0100 Subject: [PATCH 4/4] setup language first --- src/router/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/router/index.ts b/src/router/index.ts index ea740a8b..20ae2bf9 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -126,6 +126,7 @@ const router = createRouter({ router.beforeEach(async (to, from, next) => { + useSynopsisStore().setupLanguage(to.params.language) let translations = [] for (let i = 0; i< useSynopsisStore().synopses.length; i++) { @@ -136,7 +137,6 @@ router.beforeEach(async (to, from, next) => { await useSynopsisStore().loadSynopsis((to.params.translation as string).toLowerCase()) } useSynopsisStore().loadSynopses() - useSynopsisStore().setupLanguage(to.params.language) useSynopsisStore().setupTranslation(to.params.translation, options) const requiresLanguage = to.matched.some((record) => {