Get the locale within middleware #1356
-
In my middleware function, I'm making use of the
What is the best way to get the user's locale in middleware? When I try and use Some suggestions would be appreciated 😊 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
That's a good question! The negotiated locale is currently not returned from the middleware and is only available after the middleware has finished executing (e.g. in components). Can you tell me a bit more about your use case, i.e. what kind of response headers you'd like to add based on the negotiated locale? As you've noticed, as a workaround you can read from It seems like on the Next.js side there's some work happening on a new middleware architecture, so for the time being I'm trying to collect use cases that could potentially be considered if the |
Beta Was this translation helpful? Give feedback.
That's a good question! The negotiated locale is currently not returned from the middleware and is only available after the middleware has finished executing (e.g. in components).
Can you tell me a bit more about your use case, i.e. what kind of response headers you'd like to add based on the negotiated locale?
As you've noticed, as a workaround you can read from
x-middleware-request-x-next-intl-locale
. This is a private API, but it will not be removed in a non-major version and also not as long as there's no replacement for this.It seems like on the Next.js side there's some work happening on a new middleware architecture, so for the time being I'm trying to collect use cases that could…