[Docs]: Change locale in App Router without-i18n-routing #1342
Replies: 1 comment 1 reply
-
The reason is because this really depends on the approach that you've used in your app. If you're using a cookie-based approach, you might want to refer to the example App Router without i18n routing that is linked at the bottom of the getting started guide you're referring to. While creating the example I've found that it's sufficient to call Depending on your app, esp. if you don't use cookies, you might need to call I'm going to move this to a discussion for now. |
Beta Was this translation helpful? Give feedback.
-
Link to page
https://next-intl-docs.vercel.app/docs/getting-started/app-router/without-i18n-routing
Describe the problem
I'm using next-intl in the App Router without-i18n-routing configuration.
Point 3 of the linked documentation reports:
But say nothing about how to handle changes in that user setting.
As example, consider the case in which the language is stored in a database (language is a general app setting). When someone changes the database, we expect the language to change too.
So we need a way to refresh the getLocale() calling.
Currently, the only way I found to achieve this is by using both
revalidatePath("/", "layout")
(on the server) androuter.refresh()
(on the client)I have a subscription on my database key changes, once I see a change, i trigger a rootLayout revalidation by using
revalidatePath("/", "layout")
and then notify the client to refresh the router viarouter.refresh()
But this solution does not seem stable (see below).
My question (and suggestion for a doc updates) is: is this the correct way to handle locale changes without-i18n-routing?
NOTE:
I said that 'seems not stable' because I saw that next js hits cache while revalidating path. In fact, I see the cookie
x-nextjs-cache: HIT
in the header response of therevalidatePath("/", "layout")
Looking at your 790, it seems to me that all the magic to avoid cache hitting is done in the middleware, which is not required in the without-i18n-routing
Beta Was this translation helpful? Give feedback.
All reactions