From fda9ceb9b51192668e84469165fc49b28de5eedc Mon Sep 17 00:00:00 2001 From: Bill Barry Date: Mon, 10 Jan 2022 08:49:44 -0500 Subject: [PATCH] fix(@angular-devkit/build-angular): load translations fresh start Currently when making a change while serving a localized application, duplicate translation warnings appear for every translation id. This fixes that by replacing the whole translation object with a new one each time translations are loaded. fixes #22398 --- .../build_angular/src/utils/i18n-options.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/utils/i18n-options.ts b/packages/angular_devkit/build_angular/src/utils/i18n-options.ts index da6652062b25..8bce4ab4d9e9 100644 --- a/packages/angular_devkit/build_angular/src/utils/i18n-options.ts +++ b/packages/angular_devkit/build_angular/src/utils/i18n-options.ts @@ -283,6 +283,7 @@ export function loadTranslations( logger: { warn: (message: string) => void; error: (message: string) => void }, usedFormats?: Set, ) { + let translations: Record|null = null; for (const file of desc.files) { const loadResult = loader(path.join(workspaceRoot, file.path)); @@ -307,16 +308,17 @@ export function loadTranslations( if (desc.translation) { // Merge translations for (const [id, message] of Object.entries(loadResult.translations)) { - if (desc.translation[id] !== undefined) { + if (translations[id] !== undefined) { logger.warn( `WARNING [${file.path}]: Duplicate translations for message '${id}' when merging`, ); } - desc.translation[id] = message; + translations[id] = message; } } else { // First or only translation file - desc.translation = loadResult.translations; + translations = loadResult.translations; } } + desc.translation = translations; }