From c87a38f5b25b3cddd1b2a1ee4b443b10cf03b767 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Tue, 21 Jan 2025 07:23:02 +0000 Subject: [PATCH] fix(@angular/build): only issue invalid i18n config error for duplicate `subPaths` with inlined locales The i18n configuration validation was incorrectly flagging errors for identical `subPaths` when both locales were not inlined within the same build. This was due to the validation not properly accounting for the inlining of locales. This commit fixes this issue by ensuring that the validation only checks for duplicate `subPaths` when the locales are inlined. Closes #29398 (cherry picked from commit 334ec0f363e7defba8c848d281471374bea561d5) --- .../angular/build/src/utils/i18n-options.ts | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/packages/angular/build/src/utils/i18n-options.ts b/packages/angular/build/src/utils/i18n-options.ts index dc80bf8cc1d7..822683bef03d 100644 --- a/packages/angular/build/src/utils/i18n-options.ts +++ b/packages/angular/build/src/utils/i18n-options.ts @@ -199,8 +199,24 @@ export function createI18nOptions( } } - // Check that subPaths are unique. - const localesData = Object.entries(i18n.locales); + if (inline === true) { + i18n.inlineLocales.add(i18n.sourceLocale); + Object.keys(i18n.locales).forEach((locale) => i18n.inlineLocales.add(locale)); + } else if (inline) { + for (const locale of inline) { + if (!i18n.locales[locale] && i18n.sourceLocale !== locale) { + throw new Error(`Requested locale '${locale}' is not defined for the project.`); + } + + i18n.inlineLocales.add(locale); + } + } + + // Check that subPaths are unique only the locales that we are inlining. + const localesData = Object.entries(i18n.locales).filter(([locale]) => + i18n.inlineLocales.has(locale), + ); + for (let i = 0; i < localesData.length; i++) { const [localeA, { subPath: subPathA }] = localesData[i]; @@ -215,19 +231,6 @@ export function createI18nOptions( } } - if (inline === true) { - i18n.inlineLocales.add(i18n.sourceLocale); - Object.keys(i18n.locales).forEach((locale) => i18n.inlineLocales.add(locale)); - } else if (inline) { - for (const locale of inline) { - if (!i18n.locales[locale] && i18n.sourceLocale !== locale) { - throw new Error(`Requested locale '${locale}' is not defined for the project.`); - } - - i18n.inlineLocales.add(locale); - } - } - return i18n; }