-
Notifications
You must be signed in to change notification settings - Fork 467
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
Change browser language detection to only redirect from default locale route #455
Comments
someone has a fix ? |
@laurentdebricon A quick workaround konr4d@37f394d Edit: I was able to make nuxt-i18n redirect from root path only and respect the saved cookie. E.g., a new user from France is initially redirected to /fr per hers/his Accept-Language. Then, every |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue behaviour should be implement by default, as currently this module can crash a website when using the final segment of the url as a variable to fetch data, which is a normal pattern in vue and nuxt. Example: In English, 'this-is-a-page' is used to fetch the contents to the database. As it stands, if the user opens the page https://example.com/pt/paginas/esta-e-uma-pagina but its browser autodetects its English, it will update the route to https://example.com/en/pages/esta-e-uma-pagina. However, this page does not exist, thus crashing, or displaying the content in a different language. IMO, the user should see the content of the link he clicked. That's what he expects when he clicks, let's say, on a social media shared post. If he wants to change language afterwards, its his call (sometimes the translated content might even not exist in the same fashion, or different services are provided in different countries). The workaround from @konr4d is awesome, and solves this issue. I never done a PR, but I'll make one with @konr4d code (if he doesn't mind), as this issue has affected me already a few times. |
@urbgimtam Why is it redirecting to invalid https://example.com/en/pages/esta-e-uma-pagina route? Isn't that the main problem in your case? I think the problem I've described in this issue is different from yours (even if fix for this issue would likely also fix your case). |
@rchl This is a colateral damage/another symptom of the same issue. In my example, if the users browser is english but he visits the portuguese page url, it is expected to result in the portuguese page, exactly like you say. However, the current status of nuxt-i18n does not behave like that. It tries to detect the browsers language and redirect accordingly, and by doing so, it overrides the language present in the url. What I tried to say was that this behavior, in conjunction with the common pattern of using the last segment of the url as a variable in vue/nuxt, ends up generating errors. In your case, from what I understand, is the same issue: the user wants to go to a non-default locale, but the detectBrowserLanguage takes over, generating the language cookie AND redirecting to that detected language. The solution presented by @konr4d allows that behavior in the following fashion: In root path:
In any other path:
The main difference is that there's no redirection, and the full path is honored. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I can see that there is a pr which would fix/change this behaviour (#603). Any idea when/if this will be included? |
…ocale Don't attempt to detect browser's language when user (or crawler) goes directly to a page with a locale prefix if that locale is not the default one. This is to avoid redirecting user that potentially wanted to load that specific page rather than the one matching browser's language. Resolves #455 Resolves #761
…ocale Don't attempt to detect browser's language when user (or crawler) goes directly to a page with a locale prefix if that locale is not the default one. This is to avoid redirecting user that potentially wanted to load that specific page rather than the one matching browser's language. Resolves #455 Resolves #761
Don't attempt to detect browser's language when user (or crawler) goes directly to a page with a locale prefix if that locale is not the default one. This is to avoid redirecting user that potentially wanted to load that specific page rather than the one matching browser's language. Resolves #455 Resolves #761
Fix released in v6.15.0 |
What problem does this feature solve?
When using strategies with prefixes, and
detectBrowserLanguage
enabled, when user goes directly to a route with non-default locale, it would be better if we didn't redirect to browser's locale. The user's intention, in theory, was to visit the site in that specific localeSome more context in #451
What does the proposed changes look like?
Only redirect and change locale if first navigation is to route that matches
defaultLocale
.That would be a breaking change and would require major version.
The text was updated successfully, but these errors were encountered: