Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): clean translations when reloading
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alan-agius4 committed Jan 11, 2022
1 parent 39c95da commit 84cf3e8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/angular_devkit/build_angular/src/utils/i18n-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ export function loadTranslations(
logger: { warn: (message: string) => void; error: (message: string) => void },
usedFormats?: Set<string>,
) {
let translations: Record<string, unknown>|undefined = undefined;
for (const file of desc.files) {
const loadResult = loader(path.join(workspaceRoot, file.path));

Expand All @@ -304,19 +305,20 @@ export function loadTranslations(
file.format = loadResult.format;
file.integrity = loadResult.integrity;

if (desc.translation) {
if (translations) {
// 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;
}

0 comments on commit 84cf3e8

Please sign in to comment.