title: Setting locale on page load in React-Admin v3
body: <p>I've been using React-Admin v2 and now is time to upgrade to the next major version. My app has a functionality to change the language of the login page on page load, for example depending on the url params. If there isn't any param set, the language will be English, but if the url is for example myproject.tld/login/fi, the language will be Finnish. The language is changed within the <code>componentDidMount</code> by dispatching the <code>CHANGE_LOCALE</code> action, by using the <code>changeLocale</code> action creator.</p>
  <p>However, I've read the upgrade guide and it says that the translation system will not work the same way anymore, it <a href="https://github.com/marmelab/react-admin/blob/master/UPGRADE.md#the-translation-layer-no-longer-uses-redux" rel="nofollow noreferrer">no longer uses redux</a>. I've been able to get familiar with the new system, and I managed to create the buttons for language change, and it worked. It was easy to create a locale switcher function and use hook <code>useSetLocale</code> inside it.</p>
  <p>But, I still have situations, when the language must be changed on the fly without any user action, meaning clicking the buttons. I can live with the fact, if I can't get the login page translated based on the link user clicks and lands to the site. The default is English, and I can create language links on the top-right corner, if user wants to see the login form in other language.</p>
  <p>The more important thing still is to change the UI language after user login. Every user has their selected language saved to the user object in the backend, and after the successful login my React app knows the language code.</p>
  <p>The main question: How can I change the language after login and only after that load all of the content? If I have understood correctly, the hooks can't be used for example within <code>componentDidMount</code>. The methods for changing the language that I'm currently aware are 1. the hook <code>useSetLocale</code> and 2. initializing it in <code>App.js</code> file like this:</p>
  <pre><code>import * as React from &quot;react&quot;;
  import { Admin, Resource } from 'react-admin';
  import polyglotI18nProvider from 'ra-i18n-polyglot';
  import jsonServerProvider from 'ra-data-json-server';
  import UserList from './users';
  import englishMessages from 'ra-language-english';
  import finnishMessages from 'ra-language-finnish';
  
  const messages = {
      fi: finnishMessages,
      en: englishMessages,
  };
  
  const dataProvider = jsonServerProvider('https://jsonplaceholder.typicode.com');
  const i18nProvider = polyglotI18nProvider(locale =&gt; messages[locale], &quot;en&quot;);
  
  const App = () =&gt; (
      &lt;Admin
          dataProvider={dataProvider}
          i18nProvider={i18nProvider}
      &gt;
          &lt;Resource name=&quot;users&quot; list={UserList} /&gt;
      &lt;/Admin&gt;
  );
  
  export default App;
  </code></pre>
  <p>Of course that is just a test code and the code is not currently using my real backend. But is there any way to change the language after successful login and when the user chosen language is known? Is there some third way to force the language, or can I somehow re-initialize the <code>i18nProvider</code> that has been set to use English by default?</p>