Skip to content

Get the locale within middleware #1356

Answered by amannn
jamiematthews21 asked this question in Q&A
Discussion options

You must be logged in to vote

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…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@jamiematthews21
Comment options

@amannn
Comment options

@jamiematthews21
Comment options

@amannn
Comment options

@jamiematthews21
Comment options

Answer selected by jamiematthews21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants