Skip to content

Commit acf7532

Browse files
bbarryalan-agius4
authored andcommitted
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
1 parent 0421cb5 commit acf7532

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

packages/angular_devkit/build_angular/src/utils/i18n-options.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ export function loadTranslations(
310310
usedFormats?: Set<string>,
311311
duplicateTranslation?: I18NTranslation,
312312
) {
313+
let translations: Record<string, unknown> | undefined = undefined;
313314
for (const file of desc.files) {
314315
const loadResult = loader(path.join(workspaceRoot, file.path));
315316

@@ -331,10 +332,10 @@ export function loadTranslations(
331332
file.format = loadResult.format;
332333
file.integrity = loadResult.integrity;
333334

334-
if (desc.translation) {
335+
if (translations) {
335336
// Merge translations
336337
for (const [id, message] of Object.entries(loadResult.translations)) {
337-
if (desc.translation[id] !== undefined) {
338+
if (translations[id] !== undefined) {
338339
const duplicateTranslationMessage = `[${file.path}]: Duplicate translations for message '${id}' when merging.`;
339340
switch (duplicateTranslation) {
340341
case I18NTranslation.Ignore:
@@ -348,11 +349,12 @@ export function loadTranslations(
348349
break;
349350
}
350351
}
351-
desc.translation[id] = message;
352+
translations[id] = message;
352353
}
353354
} else {
354355
// First or only translation file
355-
desc.translation = loadResult.translations;
356+
translations = loadResult.translations;
356357
}
357358
}
359+
desc.translation = translations;
358360
}

0 commit comments

Comments
 (0)