From 399eb32d1196d51328a2f04ecc84235d9f7bd2db 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 --- .../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 81d9bcc02a89..9bf25f4bf581 100644 --- a/packages/angular/build/src/utils/i18n-options.ts +++ b/packages/angular/build/src/utils/i18n-options.ts @@ -193,8 +193,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]; @@ -209,19 +225,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; }