Skip to content

Commit

Permalink
fix(@angular/build): only issue invalid i18n config error for duplica…
Browse files Browse the repository at this point in the history
…te `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
  • Loading branch information
alan-agius4 committed Jan 21, 2025
1 parent 838c550 commit 334ec0f
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions packages/angular/build/src/utils/i18n-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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;
}

Expand Down

0 comments on commit 334ec0f

Please sign in to comment.