title: Multilanguage in react using redux
body: <p>I'm new to React (but I already made a simple app with ReactNative). I made a simple web app with few components to make a user login. The problem is that it must support multilang and I can't totally understand how to use redux in order to change the system language from the child component 'Menu' to all the components that are or will be loaded inside the app.</p>
  
  <p>Here are the main components:</p>
  
  <p>index.js</p>
  
  <pre><code>import React from 'react';
  import ReactDOM from 'react-dom';
  
  import App from './App';
  import * as serviceWorker from './serviceWorker';
  
  ReactDOM.render(
      &lt;App /&gt;,
      document.getElementById('root')
  );
  </code></pre>
  
  <p>App.js</p>
  
  <pre><code>import React, {Component} from 'react';
  import { BrowserRouter as Router, Route, Link, Redirect } from "react-router-dom";
  
  import Globals from './globals/globals.js';
  
  import './assets/css/main.css';
  
  import Menu from './components/Menu.js';
  import Footer from './components/Footer.js';
  import Loading from './components/Loading.js';
  
  import Login from './pages/Login.js';
  import Home from './pages/Home.js';
  
  export default class App extends Component {
  
      constructor(props) {
          super(props);
          this.state = {
              language: "en",
              accessToken: "",
              isLogged: undefined,
          }
      }
  
      componentDidMount(props) {
          // Get access token if stored
          let accessToken = localStorage.getItem('accessToken');
  
          if ( accessToken !== undefined &amp;&amp; accessToken !== null &amp;&amp; accessToken !== '' ) {
              // Try to contact the server to see if it's still viable
  
          } else {
              // Go to the login page because you're certainly not logged
              localStorage.setItem( 'accessToken', "" );
              this.setState({
                  accessToken: "",
                  isLogged: false,
              });
          }
      }
  
      render() {
          let redirect;
          if ( this.state.isLogged === false ) {
              redirect = &lt;Redirect to={{ pathname: '/login' }} /&gt;;
          }
  
          let pages;
          if ( this.state.isLogged === undefined ) {
              pages = &lt;Loading/&gt;;
          } else {
              pages = &lt;div&gt;
                  &lt;Route exact path="/" component={Home} /&gt;
                  &lt;Route path="/login" component={Login} /&gt;
              &lt;/div&gt;;
          }
  
          return(
                  &lt;Router&gt;
                      &lt;div className="page-wrapper"&gt;
                          &lt;Menu /&gt;
                          &lt;div className="site-content"&gt;
                              {pages}
                              {redirect}
                          &lt;/div&gt;
                          &lt;Footer /&gt;
                      &lt;/div&gt;
                  &lt;/Router&gt;
          );
      }
  
  }
  </code></pre>
  
  <p>Menu.js</p>
  
  <pre><code>import React, { Component } from 'react';
  import logo from './../assets/img/logo.png';
  
  export default class Menu extends Component {
  
      constructor(props) {
          super(props);
  
          this.state = {
              language: "en",
              menuState: 0,
          }
      }
  
      toggleMenu() {
          this.setState({
              menuState: 1 - this.state.menuState
          });
      }
  
      changeLanguage(language) {
          alert('change language');
      }
  
      render() {
          return(
              &lt;header&gt;
                  &lt;div className="menu-bar"&gt;
                      &lt;div className="top-bar"&gt;
                          &lt;div className="icon open" onClick={this.toggleMenu.bind( this )}&gt;&lt;/div&gt;
                          &lt;div className="logo-wrapper"&gt;
                              &lt;img src={logo} alt="logo" /&gt;
                          &lt;/div&gt;
                          &lt;div className="language-selection-wrapper"&gt;&lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div className={this.state.menuState === 1 ? "menu-body opened" : "menu-body closed"}&gt;
                          &lt;div className="menu-sidebar"&gt;
                              &lt;div className="sidebar-content"&gt;
                                  &lt;div className="sidebar-top-bar"&gt;
                                      &lt;div className="icon close" onClick={this.toggleMenu.bind( this, 1 )}&gt;&lt;/div&gt;
                                      &lt;div className="logo-wrapper"&gt;
                                          &lt;img src={logo} alt="logo" /&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
                                  &lt;div className="language-selection-wrapper"&gt;
                                      &lt;div className={this.state.language === 'it' ? "language current" : "language"} onClick={this.changeLanguage.bind(this, 'it')}&gt;IT&lt;/div&gt;
                                      &lt;div className={this.state.language === 'en' ? "language current" : "language"} onClick={this.changeLanguage.bind(this, 'en')}&gt;EN&lt;/div&gt;
                                      &lt;div className={this.state.language === 'de' ? "language current" : "language"} onClick={this.changeLanguage.bind(this, 'de')}&gt;DE&lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/header&gt;
          );
      }
  
  }
  </code></pre>
  
  <p>And at the end Login.js</p>
  
  <pre><code>import React, { Component } from 'react';
  
  import Globals from './../globals/globals.js';
  
  import Loading from './../components/Loading.js';
  
  import 'font-awesome/css/font-awesome.min.css';
  
  export default class Login extends Component {
  
      constructor(props) {
          super(props);
  
          this.state = {
              language: "en",
              loading: false
          }
      }
  
      componentDidMount(){
          document.title = "Login"
      }
  
      doLogin() {
          alert('Fai il login');
          this.setState({
              loading: true
          });
      }
  
      render() {
          let loading;
          if ( this.state.loading === true ) {
              loading = &lt;Loading/&gt;;
          }
  
          return(
              &lt;div className="login-box"&gt;
                  &lt;div className="welcome-message"&gt;
                      {Globals.messages.welcome[this.state.language]}
                  &lt;/div&gt;
                  &lt;div className="input-wrapper"&gt;
                      &lt;input type="text" name="username" placeholder={Globals.placeholders.email[this.state.language]} /&gt;
                  &lt;/div&gt;
                  &lt;div className="input-wrapper"&gt;
                      &lt;input type="password" name="password" placeholder={Globals.placeholders.password[this.state.language]} /&gt;
                  &lt;/div&gt;
                  &lt;div className="input-wrapper"&gt;
                      &lt;button type="button" onClick={this.doLogin.bind(this)}&gt;&lt;i className="fa fa-sign-in"&gt;&lt;/i&gt;&lt;span&gt;{Globals.placeholders.login[this.state.language]}&lt;/span&gt;&lt;/button&gt;
                  &lt;/div&gt;
                  {loading}
              &lt;/div&gt;
          );
      }
  
  }
  </code></pre>
  
  <p>I'm also giving the globals.js file with translations</p>
  
  <pre><code>const Globals = {
      baseUrl: "https://www.mywebsite.it/webservices/1.0/",
  
      messages: {
          welcome: {
              it: "Benvenuto!",
              en: "Welcome!",
              de: "Willkommen!",
          },
      },
  
      placeholders: {
          email: {
              it: "Email",
              en: "Email",
              de: "Email",
          },
          password: {
              it: "Password",
              en: "Password",
              de: "Password",
          },
          login: {
              it: "Login",
              en: "Login",
              de: "Login",
          },
      },
  }
  
  export default Globals;
  </code></pre>