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

Automatic Language dectection seems to work only in Chrome when locale is only partially in locales #18334

Closed
alveshelio opened this issue Oct 27, 2020 · 3 comments
Assignees
Milestone

Comments

@alveshelio
Copy link

Bug report

In Firefox or Safari, automatic language detection doesn't seem to work properly if in locales we have ["pt-PT"] but Accept-Language is "pt" for example

According to the documentation: https://nextjs.org/docs/advanced-features/i18n-routing#automatic-locale-detection

When a user visits the application root (generally /), Next.js will try to automatically detect which locale the user prefers based on the Accept-Language header and the current domain.

However, if in next.config.js we have locales: ['en-CA', 'fr-CA', 'pt-PT'] and we've defined the browser language to pt then NextJS will fail to set locale as 'pt-PT' and will instead set locale as the defaultLocale

So unless the browser language is exactly the same as in locales, automatic language detection won't work.

Clone this example https://github.com/vercel/next.js/tree/canary/examples/i18n-routing

Then change locales to something like ["en-CA", "fr-CA", "pt-PT"] or a language of your choice but it needs to be xx-XX and set `defaultLocale: "en-CA"

Then change your browser language to one of the languages in locales but instead make sure you only have xx, for example en or fr or pt or whatever languages you've added to your locales.

Navigate to the index page and you should be redirected to http://localhost:3000/pt or the language you've set your browser to.

Instead you stay on http://localhost:3000

I'm not sure it's a bug in NextJS though since it works in Chrome but fails in both Firefox and Safari.

@theostrahlen
Copy link
Contributor

I have the same issue but also in Chrome.
I have locales: ['en-US', 'sv-SE'] in my next.config.js but automatic detection for Swedish only works if I change it to sv.

@Timer Timer modified the milestone: iteration 11 Oct 28, 2020
@Timer Timer added the point: 2 label Oct 30, 2020
@Timer Timer modified the milestones: iteration 11, iteration 12 Oct 30, 2020
@Timer Timer modified the milestones: iteration 12, iteration 13 Nov 12, 2020
@ijjk
Copy link
Member

ijjk commented Nov 17, 2020

Closing in favor of #18676

@ijjk ijjk closed this as completed Nov 17, 2020
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants