Skip to content

Commit

Permalink
i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Sep 11, 2023
1 parent 33c081d commit 8467d0e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 16 deletions.
6 changes: 6 additions & 0 deletions generators/languages/files.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ export const clientI18nFiles = {
'user-management.json',
],
},
{
condition: ctx => ctx.clientFrameworkVue,
path: `${CLIENT_MAIN_SRC_DIR}/i18n/`,
renameTo: context => `${context.clientSrcDir}/i18n/${context.lang}/${context.lang}.js`,
templates: ['index.js'],
},
{
from: context => `${CLIENT_MAIN_SRC_DIR}/i18n/${context.lang}/`,
to: context => `${context.clientSrcDir}/i18n/${context.lang}/`,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { all } from 'deepmerge';

export default all(Object.values(import.meta.glob('./*.json', { import: 'default', eager: true })));
1 change: 1 addition & 0 deletions generators/vue/resources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"bootstrap": "4.6.2",
"bootstrap-vue": "2.23.1",
"bootswatch": "5.3.1",
"deepmerge": "^4.3.1",
"js-cookie": "3.0.5",
"pinia": "2.1.6",
"vue": "3.3.4",
Expand Down
14 changes: 0 additions & 14 deletions generators/vue/support/update-languages.mts
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,10 @@ function updateLanguagesInConfigTask(this: BaseGenerator, { application, control
);
}

function updateLanguagesInWebpackTask(this: BaseGenerator, { application, control = {} }: UpdateClientLanguagesTaskParam) {
const { clientSrcDir, languages } = application;
const { ignoreNeedlesError: ignoreNonExisting } = control;
let newContent = 'groupBy: [\n';
languages?.forEach(language => {
newContent += ` { pattern: './${clientSrcDir}i18n/${language}/*.json', fileName: './i18n/${language}.json' },\n`;
});
newContent += ' // jhipster-needle-i18n-language-webpack - JHipster will add/remove languages in this array\n ]';

this.editFile('webpack/webpack.common.js', { ignoreNonExisting }, content =>
content.replace(/groupBy:.*\[([^\]]*jhipster-needle-i18n-language-webpack[^\]]*)\]/g, newContent),
);
}

export default function updateLanguagesTask(this: BaseGenerator, taskParam: UpdateClientLanguagesTaskParam) {
updateLanguagesInPipeTask.call(this, taskParam);
updateLanguagesInConfigTask.call(this, taskParam);
updateLanguagesInWebpackTask.call(this, taskParam);
updateLanguagesInDayjsConfigurationTask.call(this, taskParam, {
configurationFile: `${taskParam.application.clientSrcDir}app/shared/config/dayjs.ts`,
commonjs: true,
Expand Down
1 change: 1 addition & 0 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": "<%= nodeDependencies['deepmerge'] %>",
"vue-i18n": "<%= nodeDependencies['vue-i18n'] %>",
<%_ } _%>
"vue-router": "<%= nodeDependencies['vue-router'] %>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export default class TranslationService {

public async refreshTranslation(newLanguage: string) {
if (this.i18n && !this.i18n.messages[newLanguage]) {
const res = await axios.get(`i18n/${newLanguage}.json?_=${I18N_HASH}`);
this.i18n.setLocaleMessage(newLanguage, res.data);
const translations = (await import(`../../i18n/${newLanguage}/${newLanguage}.js`)).default;
this.i18n.setLocaleMessage(newLanguage, translations);
}
}

Expand Down

0 comments on commit 8467d0e

Please sign in to comment.