A very basic react-intl
setup.
- We have a HOC
withIntl
that injectst()
as prop to our localized components.t()
is just a wrapper around thereact-intl
formatMessage
function. - We have a
IntlProvider
component that wraps our whole application and provides the translated messages and loads the locale data. We are usingRelay
to get the locale of the user, but you can do it any way you want. - Sample de.js that hold our German translations.
- In our
Example
component we can call thet()
. We can pass values or not depending on the translated message.
We are using the english translations (Hello, {name}
) as an ID, but you can have arbitrary IDs (hello_firstName
).
Read the docs: https://github.com/yahoo/react-intl
Nice :)
My first thought is to extract something like:
I guess there would be some setting to use
[]
for interpolation instead of the{}
inreact-intl
.