Repository navigation
fix(i18n): generate fallbacks for pages with filenames containing locale keys - #14690
Conversation
…ale keys Fixes a bug where Astro's i18n fallback system with fallbackType: 'rewrite' would not generate fallback files for pages whose filename started with a locale key. Fixes: withastro#14359
🦋 Changeset detectedLatest commit: 739b61e The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
CodSpeed Performance ReportMerging #14690 will not alter performanceComparing Summary
Footnotes |
| for (const locale of filteredLocales) { | ||
| for (const route of setRoutes) { | ||
| if (!route.route.includes(`/${locale}`)) { | ||
| if (!route.route.startsWith(`/${locale}/`) && route.route !== `/${locale}`) { |
There was a problem hiding this comment.
I believe we need stricter, more refined checks. The new code assumes the locale is always at the start of the route, which isn't always the case.
What do you think about this alternative:
const hasLocaleInRoute = route.route.split('/').some(routePath => routePath === locale);
if (!hasLocaleInRoute && route.route !== `/${locale}`) {}There was a problem hiding this comment.
Thanks! Really good catch!
I think the second clause should be covered by the new approach, and I think includes is cleaner than some. Otherwise, I’ll take this change as-is:
const hasLocaleInRoute = route.route.split('/').includes(locale);
if (!hasLocaleInRoute) {
continue;
}(Also realised that I had to update a comment)
Changes
Fixes a bug where Astro's i18n fallback system with
fallbackType: 'rewrite'would not generate fallback files for pages whose filename started with a locale key.Closes: #14359
(PS. This is my first PR in this project, so please let me know if I have missed anything)
Testing
Docs
N/A: Bug fix