Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Sep 13, 2023
1 parent f1dcb9b commit 3bc7738
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
9 changes: 3 additions & 6 deletions generators/vue/templates/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"pinia": "<%= nodeDependencies.pinia %>",
"vue": "<%= nodeDependencies['vue'] %>",
<%_ if (enableTranslation) { _%>
"deepmerge": null,
"vue-i18n": "<%= nodeDependencies['vue-i18n'] %>",
<%_ } _%>
"vue-router": "<%= nodeDependencies['vue-router'] %>"
Expand Down Expand Up @@ -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'] %>",
Expand Down Expand Up @@ -119,13 +114,15 @@
"cypress": "<%= nodeDependencies['cypress'] %>",
<%_ } _%>
"rimraf": "<%= nodeDependencies['rimraf'] %>",
"rollup-plugin-copy": null,
"sass": "<%= nodeDependencies['sass'] %>",
"sinon": "<%= nodeDependencies['sinon'] %>",
"swagger-ui-dist": "<%= nodeDependencies['swagger-ui-dist'] %>",
"eslint": "<%= nodeDependencies['eslint'] %>",
"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'] %>"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
<%_ } _%>
}
}

Expand Down

0 comments on commit 3bc7738

Please sign in to comment.