Next.js Discord

Discord Forum

Automatic Locale Detection on Routes other than /

Unanswered
Maine Coon posted this in #help-forum
Open in Discord
Maine CoonOP
Hey! Is there a way to enable automatic locale detection on routes other than the root? Because I'm using next-auth and when a user signs up, it should go to a specific onboarding route.

7 Replies

Komondor
I dont like the routes locale thing either. I'm basing my locale off of the value in the cookie NEXT_LOCALE, and if that's not present then the value in the 'accept-language' header, and if that's not present then my default locale.
Maine CoonOP
Mhm, makes sense. So there's no automated way to do it?
Komondor
There might be but I haven't found it
@Komondor There might be but I haven't found it
Maine CoonOP
Okay, thanks for your answer! Do you get those value i.e. in getServersideProps? What's your experience with what these values are when you haven't visited / yet?
Komondor
I get them in the middleware. But you can get them anywhere you have access to the request object, and the cookies (which is nearly everywhere from what I can tell)
You can visit any path on the website and they will be accessible
Mossyrose gall wasp
i think you can get user locale from Accept-Language header. i remember i made it before inside middleware nextjs appdir project.