Language middleware
Language middleware allows us to create a multi-lingual React application. Explaining each step of how it works is beyond the scope of this book. However, we will try to give a brief walk-through of how it is configured. The working code for the language middleware is in the GitHub repository inside CH06
:
- We used the
react-intl
(https://github.com/yahoo/react-intl) library for internationalization. It can be added to the application in the same way as other—yarn add react-intl
. - The
CH06
repository is configured with two locales, Norwegian and English. If you check theCH06/app/app.js
file, you will see theLanguageProvider
container. We are providing the container as the parent component of the Router so that we can change locale easily:
const render = messages => {
ReactDOM.render(
<Provider store={store}>
<LanguageProvider messages={messages}>
<ConnectedRouter history={history}>
<App />
</ConnectedRouter>...