You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
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.
The text was updated successfully, but these errors were encountered:
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.
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
locked as resolved and limited conversation to collaborators
Jan 29, 2022
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
However, if in
next.config.js
we havelocales: ['en-CA', 'fr-CA', 'pt-PT']
and we've defined the browser language topt
then NextJS will fail to set locale as 'pt-PT' and will instead setlocale
as thedefaultLocale
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 havexx
, for exampleen
orfr
orpt
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.
The text was updated successfully, but these errors were encountered: