Skip to content

Commit

Permalink
[languages] move user-management translation to entities
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Feb 2, 2024
1 parent 74d7b96 commit cdea0c3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
21 changes: 20 additions & 1 deletion generators/languages/entity-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* limitations under the License.
*/
import { getEnumInfo } from '../base-application/support/index.js';
import { CLIENT_MAIN_SRC_DIR } from '../generator-constants.js';

/**
* The default is to use a file path string. It implies use of the template method.
Expand All @@ -35,6 +36,17 @@ export const entityClientI18nFiles = {
],
};

export const userTranslationfiles = {
userTranslationfiles: [
{
from: context => `${CLIENT_MAIN_SRC_DIR}/i18n/${context.lang}/`,
to: context => `${context.clientSrcDir}/i18n/${context.lang}/`,
transform: false,
templates: ['user-management.json'],
},
],
};

export const enumClientI18nFiles = {
enumBaseFiles: [
{
Expand Down Expand Up @@ -82,13 +94,20 @@ export function writeEntityFiles() {
async writeClientFiles({ application, entities }) {
if (application.skipClient) return;
const entitiesToWriteTranslationFor = entities.filter(entity => !entity.skipClient && !entity.builtInUser);
if (application.userManagement && application.userManagement.skipClient) {
entitiesToWriteTranslationFor.push(application.userManagement);
}

// Copy each
const { clientSrcDir, frontendAppName } = application;
const languagesToApply = application.enableTranslation ? this.languagesToApply : [...new Set([application.nativeLanguage, 'en'])];
for (const entity of entitiesToWriteTranslationFor) {
for (const lang of languagesToApply) {
await this.writeFiles({ sections: entityClientI18nFiles, context: { ...entity, clientSrcDir, frontendAppName, lang } });
if (entity.builtInUserManagement) {
await this.writeFiles({ sections: userTranslationfiles, context: { ...entity, clientSrcDir, frontendAppName, lang } });
} else {
await this.writeFiles({ sections: entityClientI18nFiles, context: { ...entity, clientSrcDir, frontendAppName, lang } });
}
}
}
},
Expand Down
11 changes: 1 addition & 10 deletions generators/languages/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,7 @@ export const clientI18nFiles = {
from: context => `${CLIENT_MAIN_SRC_DIR}/i18n/${context.lang}/`,
to: context => `${context.clientSrcDir}/i18n/${context.lang}/`,
transform: false,
templates: [
'error.json',
'login.json',
'home.json',
'password.json',
'register.json',
'sessions.json',
'settings.json',
'user-management.json',
],
templates: ['error.json', 'login.json', 'home.json', 'password.json', 'register.json', 'sessions.json', 'settings.json'],
},
{
condition: ctx => ctx.clientFrameworkVue && ctx.enableTranslation && !ctx.microfrontend,
Expand Down
4 changes: 4 additions & 0 deletions generators/languages/translation-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ export default class TranslationData {
if (!data) {
return translatedValue;
}
/* workaround custom translation for UserManagement */
if (translatedValue.includes('{{ login }}') && !data.login) {
data.login = data.id;
}
const compiledTemplate = _.template(translatedValue, { interpolate: /{{([\s\S]+?)}}/g });
return compiledTemplate(data);
}
Expand Down

0 comments on commit cdea0c3

Please sign in to comment.