title: Flutter: Multi-lingual application - how to override the locale?
body: <p>I followed the explanations given in the official Flutter pages (see <a href="https://flutter.io/tutorials/internationalization/" rel="noreferrer">here</a>) to make my application work in different languages.</p>
  
  <p>According to the documentation, it retrieves the user's locale and this works fine.</p>
  
  <p>Let's now suppose that my application supports different languages (such as EN, FR, ES, ...) and that the user could select one of these languages to use the application (the selected language would then be different than the one defined in the phone's settings), how can I achieve this?</p>
  
  <p>How may I force the <strong>application</strong> Locale and dynamically "reload" all the translations?</p>
  
  <p>The Flutter page does not explain this and I haven't seen anything that help me  in the documentation...</p>
  
  <p>Here is the current implementation:</p>
  
  <pre><code>class Translations {
    Translations(this.locale);
  
    final Locale locale;
  
    static Translations of(BuildContext context){
      return Localizations.of&lt;Translations&gt;(context, Translations);
    }
  
    static Map&lt;String, Map&lt;String, String&gt;&gt; _localizedValues = {
      'en': {
        'title': 'Hello',
      },
      'fr': {
        'title': 'Bonjour',
      },
      'es': {
        'title': 'Hola',
      }
    };
  
    String text(String key){
      return _localizedValues[locale.languageCode][key] ?? '** ${key} not found';
    }
  }
  
  class TranslationsDelegate extends LocalizationsDelegate&lt;Translations&gt; {
    const TranslationsDelegate();
  
    @override
    bool isSupported(Locale locale) =&gt; ['en', 'fr','es'].contains(locale.languageCode);
  
    @override
    Future&lt;Translations&gt; load(Locale locale) {
      return new SynchronousFuture&lt;Translations&gt;(new Translations(locale));
    }
  
    @override
    bool shouldReload(TranslationsDelegate old) =&gt; false;
  }
  </code></pre>
  
  <p>In the main.dart:</p>
  
  <pre><code>class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return new MaterialApp(
        title: Translations.of(context).text('title'),
        theme: new ThemeData(
          primarySwatch: Colors.blue,
        ),
        localizationsDelegates: [
          const TranslationsDelegate(),
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
        ],
        supportedLocales: [
          const Locale('en', ''), // English
          const Locale('fr', ''), // French
          const Locale('fr', ''), // French
        ],
          home: new LandingPage(),
      );
    }
  }
  </code></pre>
  
  <p>Many thanks for your help.</p>