Skip to content

Fix i18n fallback to a locale with a custom path - #18484

Open
spokodev wants to merge 1 commit into
withastro:mainfrom
spokodev:fix/i18n-fallback-custom-path-locale
Open

spokodev wants to merge 1 commit into
withastro:mainfrom
spokodev:fix/i18n-fallback-custom-path-locale

Conversation

@spokodev

Copy link
Copy Markdown

Changes

  • i18n.fallback values are locale paths: config validation checks them against each locale's path, and in i18n object locale codes are rejected as defaultLocale in config validation #16117 the routing was confirmed to be driven by path. For a locale whose path is not one of its codes, such as { path: 'french', codes: ['fr', 'fr-CA'] }, the fallback code passed that path to getPathByLocale(), which only looks at codes, so it threw i18nNoLocaleFoundInPath. With fallback: { es: 'french' }, astro build fails with i18nNoLocaleFoundInPath while rendering /es/about.
  • The config from the type test added in Fix NormalizeLocales to extract path instead of codes for i18n type checking #18467 ({ path: 'en-us', codes: ['en-US'] } as the default locale, fallback: { french: 'en-us' }) makes computeFallbackRoute() throw the same error for a missing /french/ page.
  • The fallback value is already the locale's path, so computeFallbackRoute() and redirectToFallback() now use it directly.

Testing

  • New unit tests in fallback.test.ts (a fallback to a locale object, and a fallback to a default locale with a custom path) and in manual-routing.test.ts (redirectToFallback). They fail with i18nNoLocaleFoundInPath before the change and pass after it; reverting either call site makes its own test fail.
  • In a project with locales: ['en', 'es', { path: 'french', codes: ['fr', 'fr-CA'] }] and fallback: { es: 'french' }, astro build now succeeds and /es/about redirects to /french/about/. With fallback: { es: 'en' }, /es/about still redirects to /about/.

Docs

No docs change: this makes an existing configuration work as configured.

@changeset-bot

changeset-bot Bot commented Oct 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cd7f2a7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
astro Patch

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 22, 2026
@codspeed

codspeed Bot commented Oct 22, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning, 1 note

⚠️ 3 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

✅ 21 untouched benchmarks


Comparing spokodev:fix/i18n-fallback-custom-path-locale (cd7f2a7) with main (8ea79a2)

Open in CodSpeed

This branch has not been deployed

No deployments
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.

1 participant