Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Sep 12, 2023
1 parent 7762815 commit aad3e29
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
10 changes: 4 additions & 6 deletions generators/angular/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,10 @@ export default class AngularGenerator extends BaseApplicationGenerator {
cleanupOldFilesTask,
writeFiles,
queueTranslateTransform({ control, application }) {
if (!application.enableTranslation) {
this.queueTransformStream(translateAngularFilesTransform(control.getWebappTranslation), {
name: 'translating webapp',
streamOptions: { filter: file => isFilePending(file) && isTranslatedAngularFile(file) },
});
}
this.queueTransformStream(translateAngularFilesTransform(control.getWebappTranslation, application.enableTranslation), {
name: 'translating webapp',
streamOptions: { filter: file => isFilePending(file) && isTranslatedAngularFile(file) },
});
},
});
}
Expand Down
25 changes: 14 additions & 11 deletions generators/angular/support/translate-angular.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,25 @@ function replaceErrorMessage(getWebappTranslation, content) {
* @type {import('../generator-base.js').EditFileCallback}
* @this {import('../generator-base.js')}
*/
// eslint-disable-next-line import/prefer-default-export
export const createTranslationReplacer = getWebappTranslation => {
export const createTranslationReplacer = (getWebappTranslation, enableTranslation) => {
const htmlJhiTranslateReplacer = createJhiTransformTranslateReplacer(getWebappTranslation, { escapeHtml: true });
const htmlJhiTranslateStringifyReplacer = createJhiTransformTranslateStringifyReplacer(getWebappTranslation);
return function replaceAngularTranslations(content, filePath) {
if (/\.html$/.test(filePath)) {
content = content.replace(new RegExp(TRANSLATE_REGEX, 'g'), '');
content = replacePlaceholders(getWebappTranslation, content);
if (!enableTranslation) {
content = content.replace(new RegExp(TRANSLATE_REGEX, 'g'), '');
content = replacePlaceholders(getWebappTranslation, content);
}
content = htmlJhiTranslateReplacer(content);
content = htmlJhiTranslateStringifyReplacer(content);
}
if (/(:?route|module)\.ts$/.test(filePath)) {
content = replacePageTitles(getWebappTranslation, content);
}
if (/error\.route\.ts$/.test(filePath)) {
content = replaceErrorMessage(getWebappTranslation, content);
if (!enableTranslation) {
if (/(:?route|module)\.ts$/.test(filePath)) {
content = replacePageTitles(getWebappTranslation, content);
}
if (/error\.route\.ts$/.test(filePath)) {
content = replaceErrorMessage(getWebappTranslation, content);
}
}
return content;
};
Expand All @@ -128,8 +131,8 @@ export const createTranslationReplacer = getWebappTranslation => {
const minimatch = new Minimatch('**/*{.html,.route.ts,.module.ts}');
export const isTranslatedAngularFile = file => minimatch.match(file.path);

const translateAngularFilesTransform = getWebappTranslation => {
const translate = createTranslationReplacer(getWebappTranslation);
const translateAngularFilesTransform = (getWebappTranslation, enableTranslation) => {
const translate = createTranslationReplacer(getWebappTranslation, enableTranslation);
return passthrough(file => {
file.contents = Buffer.from(translate(file.contents.toString(), file.path));
});
Expand Down

0 comments on commit aad3e29

Please sign in to comment.