Skip to content

fix(i18n): generate fallbacks for pages with filenames containing locale keys - #14690

Merged
ematipico merged 3 commits into
withastro:mainfrom
fredriknorlin:fix/i18n-fallbacks
Nov 14, 2025
Merged

ematipico merged 3 commits into
withastro:mainfrom
fredriknorlin:fix/i18n-fallbacks

Conversation

@fredriknorlin

Copy link
Copy Markdown
Contributor

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

  • Added tests covering some different locale positions in both folders and pages (folder names turned out to also be affected).
  • Although the fix turned out to be a oneliner, I kept the tests for future cover.

Docs

N/A: Bug fix

…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-bot

changeset-bot Bot commented Oct 30, 2025 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest 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

@github-actions github-actions Bot added the pkg: astro Related to the core `astro` package (scope) label Oct 30, 2025
@codspeed

codspeed Bot commented Oct 30, 2025 •

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #14690 will not alter performance

Comparing fredriknorlin:fix/i18n-fallbacks (739b61e) with main (790d942)1

Summary

✅ 6 untouched

Footnotes

  1. No successful run was found on main (1901061) during the generation of this report, so 790d942 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

for (const locale of filteredLocales) {
for (const route of setRoutes) {
if (!route.route.includes(`/${locale}`)) {
if (!route.route.startsWith(`/${locale}/`) && route.route !== `/${locale}`) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}`) {}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@ematipico ematipico self-assigned this Nov 13, 2025

@ematipico ematipico left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

i18n fallback pages are not generated at build when page filename starts with locale key

2 participants