Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): load translations fresh start
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
bbarry authored and dgp1130 committed Jan 12, 2022
1 parent 6ca0e41 commit 92b4e06
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 92b4e06

Please sign in to comment.