Skip to content

Commit 399eb32

Browse files
committed
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
1 parent 0a98602 commit 399eb32

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

packages/angular/build/src/utils/i18n-options.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,24 @@ export function createI18nOptions(
193193
}
194194
}
195195

196-
// Check that subPaths are unique.
197-
const localesData = Object.entries(i18n.locales);
196+
if (inline === true) {
197+
i18n.inlineLocales.add(i18n.sourceLocale);
198+
Object.keys(i18n.locales).forEach((locale) => i18n.inlineLocales.add(locale));
199+
} else if (inline) {
200+
for (const locale of inline) {
201+
if (!i18n.locales[locale] && i18n.sourceLocale !== locale) {
202+
throw new Error(`Requested locale '${locale}' is not defined for the project.`);
203+
}
204+
205+
i18n.inlineLocales.add(locale);
206+
}
207+
}
208+
209+
// Check that subPaths are unique only the locales that we are inlining.
210+
const localesData = Object.entries(i18n.locales).filter(([locale]) =>
211+
i18n.inlineLocales.has(locale),
212+
);
213+
198214
for (let i = 0; i < localesData.length; i++) {
199215
const [localeA, { subPath: subPathA }] = localesData[i];
200216

@@ -209,19 +225,6 @@ export function createI18nOptions(
209225
}
210226
}
211227

212-
if (inline === true) {
213-
i18n.inlineLocales.add(i18n.sourceLocale);
214-
Object.keys(i18n.locales).forEach((locale) => i18n.inlineLocales.add(locale));
215-
} else if (inline) {
216-
for (const locale of inline) {
217-
if (!i18n.locales[locale] && i18n.sourceLocale !== locale) {
218-
throw new Error(`Requested locale '${locale}' is not defined for the project.`);
219-
}
220-
221-
i18n.inlineLocales.add(locale);
222-
}
223-
}
224-
225228
return i18n;
226229
}
227230

0 commit comments

Comments
 (0)