-
-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Locale detection could be more flexible #1369
Comments
Can you share more details about your use case why you'd want to keep cookie-based detection but not |
@amannn Sure, let me elaborate more on that with more details. Note TLDR; We are using For each tenant, we will first retrieve locale configuration via API call which includes the default locale and supported locales. Let me list down the 2 scenarios below: First time user without locale prefix in their URLA first time user might not always have locale prefix in their URL, e.g. they are redirected from another service or website so it's best to let our web app to determine the selected locale for each incoming request.
Repeated user without locale prefix in their URLA repeated user will most probably have
Hope this helps clear your doubt. 🙇♂️ |
Thanks for the details!
Can you expand on why a user wouldn't want to land on That being said, what you can do already is composing the middleware and assigning Sorry if this sounds like a workaround to you 😄. My situation is just that users sometimes ask for more flexibility and getting all use cases under one roof needs careful understanding of the use cases. Ideally, I want to support all legit use cases, but offering too many options can cause users to shoot themselves in the foot. Therefore, especially if a use case can already be achieved, I'm a bit hesitant with introducing more configuration. I've made a note of this issue in any case in #1362, might need to have a look at this again in combination with other opened discussions. |
@amannn Sure, this is because a tenant is allowed to configure their default locale in our multi-tenant web apps and they want all users who visit the web app without any locale prefix to use the default locale instead of the one from their machine.
Well, this is one workaround.
I completely agree with your perspective. I often need to dive into
Really appreciate that. |
Is your feature request related to a problem? Please describe.
Background
Although next-intl offers built-in locale detection, it follows a specific internal detection order that isn’t easily customizable for unique requirements. Currently, the only option is to disable it and create custom locale detection logic. It would be beneficial if we could configure the detection priority and leverage the existing internal logic, avoiding the need to develop detection mechanisms from scratch.
Current state
By setting
localeDetection
tofalse
will disable detection based onaccept-language
header and a potentially existing cookie value from a previous visit. This might not fit into use cases that wan to only disable either options and not both.I have a use case where I need to detect the locale from the URL and cookie, using a default locale as a fallback. The default locale will vary based on the incoming requests. I will query the default locale from the database based on the incoming requests, which will allow me to determine the default locale set for a particular user if the request contains an authentication token.
Describe the solution you'd like
Proposal
It'd be great if users can override the locale detection priority while reusing the detection logics from
next-intl
without reinventing the wheel. Users are also allowed to add their own detection logics for really unique use cases.The proposed change will disable locale detection based on the
accept-language
header while keeping the other detection methods unchanged.Describe alternatives you've considered
Disable
localeDetection
and write our own locale detection logics before executing thenext-intl
middleware.The text was updated successfully, but these errors were encountered: