A very basic react-intl setup.
- We have a HOC
withIntlthat injectst()as prop to our localized components.t()is just a wrapper around thereact-intlformatMessagefunction. - We have a
IntlProvidercomponent that wraps our whole application and provides the translated messages and loads the locale data. We are usingRelayto 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
Examplecomponent 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.