fix(i18n): prevent duplicate locale directories and incorrect redirects for existing translations #13650
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix(i18n): prevent duplicate locale directories and incorrect redirects for existing translations
Description
This PR fixes an issue with i18n fallback routes where:
/es/es/
instead of just/es/
)The bug occurs when using i18n with:
fallback: { "es": "en" }
configurationprefixDefaultLocale: false
in routing optionsWhen these settings are used, the build process incorrectly generates paths with duplicate locale prefixes for fallback routes, creating directories like
/es/es/test/item1/
with redirect files even when those pages have actual translations at/es/test/item1/
.Fix
The fix modifies the
generatePath
function to:Testing
I've verified the fix using the reproduction repo: https://github.com/asieradzk/i18ntest
With the fixed version of Astro:
/es/es/
directories are createdThe fix resolves the issue without requiring users to change their i18n configuration, allowing both:
Related Issues
Fixes #13638
#13638