-
-
Notifications
You must be signed in to change notification settings - Fork 184
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
Support providing a locale in i18n.ts
instead of reading it from the pathname (single-language workflow and prefix-less routing)
#960
Comments
Interested in this as well, though our use case is slightly different, we want the option for the locale to be determined from our DB at runtime, as our customers data will be in a particular language. So we want everything in the same language as the customer (yes we have to figure out how to handle the pages before login) ... but the setup at the moment very tied in to routing, when thats not what (we think) we need |
@smozely Yep, that's closely related I think. I've updated the issue description above and would aim to support this use case as well with the proposed feature. |
@smozely I've had time to look into a proof-of-concept and I think the approach outlined above works remarkably well! Docs need to be written and adapted yet, but I think generally this is a significantly better approach to Please see #1017 for more information and a pre-release. I'd be really happy if you could help to try out the pre-release to make sure this works as expected for you! |
Very interested in this |
@ScreamZ Feel free to try out the pre-release and let me know if this works well for you! |
i18n.ts
instead of reading it from the pathname (single-language workflow and prefix-less routing)
I am looking for answer to this question #892 (comment) - I also want to take locale from user settings. AND I have the pages router. The solution to set it in getRequestConfig is only relevant for app router, correct? (I am quite new to next-intl so sorry if my question is out of place.) So how to do this in pages router? Thanks ✌️✌️ |
@branislavbrincko In the Pages Router you should be able to assign the |
@amannn We've had a quick play and its behaving how we want. Thanks! |
Is your feature request related to a problem? Please describe.
While handling multiple languages is the common case,
next-intl
is also expected to work well for apps that only support a single language. After all, if using internationalization right from the start is easier than hardcoding text and formatting, then this should be a common workflow. The Pages Router integration was already capable of this, but ideally we support this similarly for the App Router as well.Additionally, some apps read the locale from user settings and don't require it to be available in the URL. This use case is closely related (see also #892 and #778).
Describe the solution you'd like
Maybe a
locale
could be returned ini18n.tsx
:The tricky part is that we currently attempt to fetch the
locale
before this function is called. Maybe it could be lazily evaluated iflocale
is read from the params passed to the function.Describe alternatives you've considered
This is already possible by supporting only a single language and setting
localePrefix
tonever
. However, the[locale]
segment is still required.For reading a locale from the db, this can be used as a workaround: #892 (comment)
With built-in support, no middleware should be required at all.
The text was updated successfully, but these errors were encountered: