From 3bc7738a01edade1ae5a83e78fe09df360a79c54 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 13 Sep 2023 16:12:33 -0300 Subject: [PATCH] fixes --- generators/vue/templates/package.json.ejs | 9 +++------ .../app/entities/entities-menu.component.ts.ejs | 4 +--- .../webapp/app/locale/translation.service.ts.ejs | 14 +++++++++++--- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/generators/vue/templates/package.json.ejs b/generators/vue/templates/package.json.ejs index ebe4638da626..0b9e3e4f0f88 100644 --- a/generators/vue/templates/package.json.ejs +++ b/generators/vue/templates/package.json.ejs @@ -49,6 +49,7 @@ "pinia": "<%= nodeDependencies.pinia %>", "vue": "<%= nodeDependencies['vue'] %>", <%_ if (enableTranslation) { _%> + "deepmerge": null, "vue-i18n": "<%= nodeDependencies['vue-i18n'] %>", <%_ } _%> "vue-router": "<%= nodeDependencies['vue-router'] %>" @@ -78,12 +79,6 @@ "webpack-dev-server": "<%= nodeDependencies['webpack-dev-server'] %>", "webpack-merge": "<%= nodeDependencies['webpack-merge'] %>", "workbox-webpack-plugin": "<%= nodeDependencies['workbox-webpack-plugin'] %>", -<%_ } else { _%> - "rollup-plugin-copy": null, - "vite": null, - <%_ if (enableTranslation) { _%> - "deepmerge": null, - <%_ } _%> <%_ } _%> "@pinia/testing": "<%= nodeDependencies['@pinia/testing'] %>", "@rushstack/eslint-patch": "<%= nodeDependencies['@rushstack/eslint-patch'] %>", @@ -119,6 +114,7 @@ "cypress": "<%= nodeDependencies['cypress'] %>", <%_ } _%> "rimraf": "<%= nodeDependencies['rimraf'] %>", + "rollup-plugin-copy": null, "sass": "<%= nodeDependencies['sass'] %>", "sinon": "<%= nodeDependencies['sinon'] %>", "swagger-ui-dist": "<%= nodeDependencies['swagger-ui-dist'] %>", @@ -126,6 +122,7 @@ "eslint-plugin-prettier": "<%= nodeDependencies['eslint-plugin-prettier'] %>", "eslint-plugin-vue": "<%= nodeDependencies['eslint-plugin-vue'] %>", "typescript": "<%= nodeDependencies['typescript'] %>", + "vite": null, "vitest": "<%= nodeDependencies.vitest %>", "vitest-sonar-reporter": "<%= nodeDependencies['vitest-sonar-reporter'] %>" }, diff --git a/generators/vue/templates/src/main/webapp/app/entities/entities-menu.component.ts.ejs b/generators/vue/templates/src/main/webapp/app/entities/entities-menu.component.ts.ejs index a78bc06c2b89..87c39b15a461 100644 --- a/generators/vue/templates/src/main/webapp/app/entities/entities-menu.component.ts.ejs +++ b/generators/vue/templates/src/main/webapp/app/entities/entities-menu.component.ts.ejs @@ -28,9 +28,7 @@ export default defineComponent({ const loadLanguage = async () => { if (microfrontendI18n) { const languageToLoad = currentLanguage.value; - const translations = (await import(`../../i18n/${languageToLoad}/${languageToLoad}.js`)).default; - - translationService.loadTranslations({ currentLanguage: languageToLoad, translations }); + await translationService.loadTranslations({ currentLanguage: languageToLoad, urlPrefix: '<%= endpointPrefix %>/', hash: I18N_HASH }); } }; diff --git a/generators/vue/templates/src/main/webapp/app/locale/translation.service.ts.ejs b/generators/vue/templates/src/main/webapp/app/locale/translation.service.ts.ejs index 6524a586efb8..3c8acfc8d8ef 100644 --- a/generators/vue/templates/src/main/webapp/app/locale/translation.service.ts.ejs +++ b/generators/vue/templates/src/main/webapp/app/locale/translation.service.ts.ejs @@ -12,17 +12,25 @@ export default class TranslationService { } <%_ if (microfrontend) { _%> - public loadTranslations({ currentLanguage, translations }: { currentLanguage: string; translations: any }) { + public loadTranslations({ currentLanguage, urlPrefix, hash }: { currentLanguage: string; urlPrefix: string; hash: string }) { if (!this.i18n) return; - - this.i18n.mergeLocaleMessage(currentLanguage, translations); + axios.get(`${urlPrefix}i18n/${currentLanguage}.json?_=${hash}`).then((res: any) => { + if (res.data) { + this.i18n.mergeLocaleMessage(currentLanguage, res.data); + } + }); } <%_ } _%> public async refreshTranslation(newLanguage: string) { if (this.i18n && !this.i18n.messages[newLanguage]) { +<%_ if (microfrontend) { _%> + const res = await axios.get(`i18n/${newLanguage}.json?_=${I18N_HASH}`); + this.i18n.setLocaleMessage(newLanguage, res.data); +<%_ } else { _%> const translations = (await import(`../../i18n/${newLanguage}/${newLanguage}.js`)).default; this.i18n.setLocaleMessage(newLanguage, translations); +<%_ } _%> } }