fix(i18n): compute current locale from route instead of request #9865
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.
Changes
Closes #9847
Closes PLT-1511
During the build, the
url.pathname
contains the the extension e.g.en.html
, so Astro could never find the correct locale.With this fix, we use
RouteData
instead, which is an object that we attach to the request using a pipeline hook. We attach this information here:astro/packages/astro/src/core/build/generate.ts
Line 284 in f27f790
And this is the value of the function
astro/packages/astro/src/i18n/middleware.ts
Lines 137 to 139 in f27f790
Testing
I modified and existing test to render the current locale
Docs
N/A