From 6780a1ade46ec8edd33e0a933d1b3bd5388416d5 Mon Sep 17 00:00:00 2001 From: Marcelo Boveto Shima Date: Thu, 1 Feb 2024 17:55:58 -0300 Subject: [PATCH] [languages] move user-management translation to entities --- generators/languages/entity-files.js | 21 ++++++++++++++++++++- generators/languages/files.js | 11 +---------- generators/languages/translation-data.js | 4 ++++ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/generators/languages/entity-files.js b/generators/languages/entity-files.js index a88aa498e073..0c78eabd71bb 100644 --- a/generators/languages/entity-files.js +++ b/generators/languages/entity-files.js @@ -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. @@ -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: [ { @@ -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 } }); + } } } }, diff --git a/generators/languages/files.js b/generators/languages/files.js index cc8547c65509..eaa4e34ee1d1 100644 --- a/generators/languages/files.js +++ b/generators/languages/files.js @@ -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, diff --git a/generators/languages/translation-data.js b/generators/languages/translation-data.js index cc3abacdf55c..d82778bb0def 100644 --- a/generators/languages/translation-data.js +++ b/generators/languages/translation-data.js @@ -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); }