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

Astro.preferredLocale is always undefined in "hybrid" output mode with prerender = false #10620

Open
1 task
stefanprobst opened this issue Mar 31, 2024 · 1 comment · May be fixed by #10662
Open
1 task

Astro.preferredLocale is always undefined in "hybrid" output mode with prerender = false #10620

stefanprobst opened this issue Mar 31, 2024 · 1 comment · May be fixed by #10662
Assignees
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: i18n Related to internalization

Comments

@stefanprobst
Copy link

Astro Info

Astro                    v4.5.12
Node                     v20.12.0
System                   Linux (x64)
Package Manager          pnpm
Output                   hybrid
Adapter                  @astrojs/node
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

i want to use Astro.preferredLocale to redirect the "/" root route to the user's preferred locale (or the default locale). i am using hybrid output mode, and have set export const prerender = false in src/pages/index.astro, and configured redirectToDefaultLocale: false in astro.config.mjs.

When logging both Astro.preferredLocale and Astro.request.headers.get("Accept-Language"), i see that Astro.preferredLocale is undefined, even though the Accept-Language headers are logged correctly.

how to reproduce

  1. clone the repo at https://github.com/stefanprobst/issue-astro-i18n-preferredlocale-hybrid
  2. pnpm run build
  3. pnpm run preview
  4. open http://localhost:3000
  5. see server logs:
Preferred locale: undefined
Accept-Language header: de,en-US;q=0.7,en;q=0.3

observations

  • when changing "output" mode from hybrid to server, it correctly prints: "Preferred locale: de"
  • when not using any import from astro:i18n, i.e. commenting out this line, it also works correctly in hybrid mode
  • changing src/pages/index.astro to a src/pages/index.ts GET route does not make a difference

What's the expected result?

see above

Link to Minimal Reproducible Example

https://github.com/stefanprobst/issue-astro-i18n-preferredlocale-hybrid

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Mar 31, 2024
@ematipico ematipico added - P3: minor bug An edge case that only affects very specific usage (priority) feat: i18n Related to internalization and removed needs triage Issue needs to be triaged labels Mar 31, 2024
@ematipico ematipico self-assigned this Apr 3, 2024
@ematipico
Copy link
Member

It seems that the prerender logic is transforming the function computePreferredLocale in a noop function. I'll have to understand why.

@ematipico ematipico linked a pull request Apr 3, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: i18n Related to internalization
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants