Repository navigation
fix(i18n): prevent duplicate locale directories and incorrect redirects for existing translations - #13650
fix(i18n): prevent duplicate locale directories and incorrect redirects for existing translations#13650asieradzk wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 380a968 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 #13650 will not alter performanceComparing Summary
|
| // Found duplicate locale - e.g., /es/es/ | ||
| normalizedPathname = '/' + pathParts.slice(1).join('/'); |
There was a problem hiding this comment.
If we arrive here es/es/, it means that the bug is coming from somewhere else. It means we are "patching" something broken, instead of fixing it. Have you figured out where the incorrect pathname is coming from?
There was a problem hiding this comment.
I can't locate it Maybe a second pair of eyes?
To summarise where I looked:
- Patched the final generation step in generate.ts
- From there I checked path generator function
getRouteGeneratorin manifest/generator.ts
Confirmed it works correctly based on the input segments it receives. It only produces /es/es/... if given incorrect segments starting with [[es], [lang], ...]. - Then I looked at RouteData logic in manifest/create,ts but the initial route was created correctly
([[lang], ...])
What could this be? The segments data appears to be correctly created and incorrectly modified after initial creation but before the final path generation.
|
Hi @asieradzk 👋 No rush at all. just checking in. |
As I said previously " The segments data appears to be correctly created and incorrectly modified after initial creation but before the final path generation." But I can't find the root cause waiting for some suggestions where to look. Maybe someone else is going to be offended by the bug in the future and we can join forces. |
|
Looks like the issue was fixed by #14020, thanks for opening this PR in the first place! |
|
@florian-lefebvre It appears that: hasn't fixed the "fallback generates redirect even for custom-provided localized routes" problem which was also discovered/fixed by @asieradzk in this PR My report on this problem: |
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: falsein 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
generatePathfunction 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