Translate specific parts of app to different locales (React) #731
-
Hi, really enjoying the library. We have a usecase in react where we want to have one locale for the user while also displaying specific parts of the app using another locale. For example, the user's preferred language may be English, but they are able to create and preview a German product that should have labels etc in that language. Currently we're using the TypesafeI18n context for the overall ui locale, but I was wondering if there's a way to create another context for the product locale and avoid conflicts. Alternatively, load multiple locales and conditionally choose which to render? Appreciate any thoughts. Update Simplified example:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Your solutoin with the contexts is exactly what I was thinking of. export const Button = () => {
return <>
<TypeSafeI18n locale={rootLocale}>
<button />
</TypeSafeI18n>
</>
} |
Beta Was this translation helpful? Give feedback.
Your solutoin with the contexts is exactly what I was thinking of.
The context approach is really flexible and you can nest them however you like. If you want certain components to be rendered in the original language then you just need to wrap them in anothr context: