-
-
Notifications
You must be signed in to change notification settings - Fork 483
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
detectBrowserLanguage
does not detect browser lang as expected
#3126
Comments
Could you provide your reproduction as a reppository or a stackblitz project? |
https://stackblitz.com/edit/nuxt-starter-824aop I found its preview page has not |
I was facing the exact same issue with server-side locale detection. The feature works in development mode, but running the app in production always redirects the user to the default locale's path. The request header To me this seems like a nuxt or h3 issue and not one with this module, but I might be wrong on this. I hope this information acts as a starting point for getting this issue resolved. Here's a workaround that manually assigns this header based on the // middleware/fix-locale-detection.global.ts
export default defineNuxtRouteMiddleware(() => {
const event = useRequestEvent();
const acceptLanguageHeader = event?.node.req.headersDistinct['accept-language']?.[0];
if (acceptLanguageHeader) {
event.node.req.headers['accept-language'] = acceptLanguageHeader;
}
}); |
Perhaps related to #2975 which does point to it being an upstream issue (Nuxt/h3) |
I think I spoke too soon, the above workaround doesn't actually fix the issue, only the symptoms of it. During testing, I saw that the feature only now works when I append some URL parameter to the URL (e.g. requesting The real fix in my case seems to be disabling the caching of the root route ( My Nuxt config had the following route rules before: // config.routeRules
{
'/**': { swr: 600 }
} I've adjusted this to be: // config.routeRules
{
'/de_de/**': { swr: 600 },
'/de_de/': { swr: 600 },
'/en_com/**': { swr: 600 },
'/en_com/': { swr: 600 },
// ... they are dynamically generated
} This resolves the issue and the feature works as expected, without the bandaid fix in the comment above. @BobbieGoede could this be the reason for the described behavior? |
I faced the same problem, when I used detectBrowserLanguage: false , it didn't work, it still adds the cookie i18n_redirected. |
Environment
Reproduction
nuxt-i18n-BUG-REPRODUCE.zip
Describe the bug
with setting:
When Browser request header has
accept-language: zh-CN,zh;q=0.9
Expect: redirect to
/zh/hello
But has:
location: /en/hello
same with issues/1632
Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: