-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
feat: allow custom languages in IntlProvider
#158
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already possible & documented:
Lines 359 to 377 in 4bdbac1
Custom translations can be provided using the `IntlProvider` from `react-intl`. | |
For reference, it is best to start with the auto-generated English defaults, as | |
they include all keys. More information on the Kratos messages can be found | |
[in the docs](https://www.ory.sh/docs/kratos/concepts/ui-user-interface#ui-message-codes). | |
```tsx | |
import { IntlProvider } from "react-intl" | |
const Main = () => { | |
return ( | |
<IntlProvider locale={customMessageLocale} messages={customMessages}> | |
<Router> | |
<Route path="/" component={Dashboard} /> | |
{/* ... */} | |
</Router> | |
</IntlProvider> | |
) | |
} | |
``` |
We could improve the docs to show how the default translations can be extended instead:
import { IntlProvider } from "react-intl"
import { locales } from "@ory/elements"
const customMessages = {
...locales,
de: {
...locales.de,
"login.title": "Login",
},
}
const Main = () => {
return (
<IntlProvider locale={customMessageLocale} messages={customMessages}>
<Router>
<Route path="/" component={Dashboard} />
{/* ... */}
</Router>
</IntlProvider>
)
}
I agree that we do support it, but it requires the user implementing the library to directly use In an optimal path scenario I can see more users wanting to only use a copy paste example with defaults and the option to override some labels, such as the login The path to reach this use case in the current method isn't as obvious and a bit confusing, especially if you have no idea which keys do what. What if we introduce breaking changes later on inside the translations? or special formatting like we do here https://github.com/ory/elements/blob/main/src/react-components/provider.tsx#L50-L52 I'm not against the current way and I think supporting it makes sense to give users a choice and the ability to customize the translation layer themselves. But a happy path must exist and i don't think the current implementation is that happy path. |
@@ -82,6 +82,91 @@ have explicitly told our React app to use through the `VITE_ORY_SDK_URL` export. | |||
Now you can see Ory Elements in action by opening <http://localhost:3000> in | |||
your browser! | |||
|
|||
## Internalization (i18n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the README to be more clear on this and moved it to the top under getting started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, this looks quite a bit more useful now 👍
Adds custom language support to the
IntlProvider
. This allows users ofory/elements
to specify and provide their own custom translations without needing to add it to theory/elements
repository.Related Issue or Design Document
Checklist
If this pull request addresses a security vulnerability,
I confirm that I got approval (please contact security@ory.sh) from the maintainers to push the changes.
Further comments