I ran into the same problem, and here is what I found out:
To change the language, I used the provided solution here , which basically associates IntlProvider with ReduxStore with the Connect function. Also, do not forget to enable the key for reprocessing components when changing the language. This is basically all the code:
This is ConnectedIntlProvider.js, just binds the standard IntlProvider (note the key pillar missing from the original github comment)
import { connect } from 'react-redux'; import { IntlProvider } from 'react-intl';
And then in your entry point file:
The next thing to do is simply implement the reducer for managing languages ββand force action creators to change languages ββon demand.
As for the best way to store translations, I found a lot of discussion on this topic, and the situation seems rather confusing, to be honest, I'm completely confused that the creators of the interactive focus pay so much attention to date and number formats and forget about the translation. So, I I donβt know the absolutely correct way to handle this, but this is what I am doing:
Create a folder "locales" and inside create a bunch of files like "en.js", "fi.js", "ru.js", etc. Basically all the languages ββyou work with.
In each file, a json object is exported with the following translations:
export const ENGLISH_STATE = { lang: 'en', messages: { 'app.header.title': 'Awesome site', 'app.header.subtitle': 'check it out', 'app.header.about': 'About', 'app.header.services': 'services', 'app.header.shipping': 'Shipping & Payment', } }
Other files have exactly the same structure, but with translated strings inside.
Then, in the reducer, which is responsible for changing the language, import all the states from these files and upload them to the redux repository as soon as the action for changing the language is sent. Your component created in the previous step will propagate changes to IntlProvider, and a new locale will take place. Display it on the page using <FormattedMessage> or intl.formatMessage({id: 'app.header.title'})} , read more about this in your github wiki.
They have a DefineMessages function, but to be honest, I could not find any good information on how to use it, basically you can forget about it and be fine.