Replies: 1 comment 3 replies
-
The Instead, you can set up your own middleware that negotiates the locale (inspiration) and then uses the result to set a cookie. Later, after signup, this part can be skipped. Just note that if you set a cookie on the response, then Server Components will not be able to read it via The result can then be used to initialize // i18n/request.ts
import {getRequestConfig} from 'next-intl/server';
export default getRequestConfig(async () => {
const locale = getLocaleFromUserProfile() || cookies().get('NEXT_LOCALE');
return {
locale,
messages: (await import(`../../messages/${locale}.json`)).default
};
}); Let me know if this helps! |
Beta Was this translation helpful? Give feedback.
-
Hello!
We are moving away from path-based routing in favour of using the user's account preference. We need to store the locale on the server too in order to know what format to send emails in etc. Our Vite desktop app is an SPA without a router, so we can't take full advantage of path-based routing now anyway.
In our NextJS web app, we would still like to rely on the Accept-Language header + Cookie combination for users who aren't logged in. That way they can still change the language before they sign up, and the language they choose can be used to create the account.
As far as I can tell looking at the source code, next-intl only updates the cookie when using path-based routing - is this correct?
Would you recommend we maintain our own cookie, or perhaps a cookie with the same name as the one used in next-into so that the middleware picks it up automatically?
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions