Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(i18n): compute current locale from route instead of request #9865

Merged
merged 2 commits into from
Jan 29, 2024

Conversation

ematipico
Copy link
Member

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:

pipeline.onBeforeRenderRoute(i18nPipelineHook);

And this is the value of the function

export const i18nPipelineHook: PipelineHookFunction = (ctx) => {
Reflect.set(ctx.request, routeDataSymbol, ctx.route);
};

Testing

I modified and existing test to render the current locale

Docs

N/A

Copy link

changeset-bot bot commented Jan 29, 2024

🦋 Changeset detected

Latest commit: 49d46e0

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 Jan 29, 2024
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
@ematipico ematipico merged commit 00ba9f1 into main Jan 29, 2024
13 checks passed
@ematipico ematipico deleted the fix/use-route-when-computing-current-locale branch January 29, 2024 14:47
@astrobot-houston astrobot-houston mentioned this pull request Jan 29, 2024
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
2 participants