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 alan-agius4 committed Jan 19, 2022
1 parent 0421cb5 commit acf7532
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 @@ -310,6 +310,7 @@ export function loadTranslations(
usedFormats?: Set<string>,
duplicateTranslation?: I18NTranslation,
) {
let translations: Record<string, unknown> | undefined = undefined;
for (const file of desc.files) {
const loadResult = loader(path.join(workspaceRoot, file.path));

Expand All @@ -331,10 +332,10 @@ 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) {
const duplicateTranslationMessage = `[${file.path}]: Duplicate translations for message '${id}' when merging.`;
switch (duplicateTranslation) {
case I18NTranslation.Ignore:
Expand All @@ -348,11 +349,12 @@ export function loadTranslations(
break;
}
}
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 acf7532

Please sign in to comment.