Best way to set the locale manually? #724
Replies: 1 comment
-
To anyone facing a similar issue, this is how I solved it.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there, I am working on migrating a legacy app to React and part of the feature set is to have multiple locale support. I have structured my locale file to have keys by use/page (ie a "Generic" key contains generic messages, "Navbar" contains the navbar's messages, "Dashboard" has the keys for the Dashboard etc). This way, each page has loads the Intl provider with the keys for itself plus the generic keys to avoid loading unnecessary translations, my page structure is like this:
The legacy app allows users to set their own custom timezone and language. Thus the React app needs to do the same, I am reading the user's preferences from the database using Sequelize and loading them using server components.
How (and where) should I override the detected language with the user-selected one? I thought about doing it in the
i18n.ts
file but 1) this does not feel right since I am overriding the default behavior and it is not clear 2) using sequelize in middleware is a pain anyway. I thought about doing it at the intl provider level but since there are several levels of nested providers this seems cumbersome, and the root layout would have the wronglang
attribute set in the document. Any ideas? Thanks.Beta Was this translation helpful? Give feedback.
All reactions