Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: Application's locale is not supported by all of its localization delegates

Hello I am trying add BottomNavigationBar in flutter app but when i run project error occures :

A MaterialLocalizations delegate that supports the ka_GE locale was not found

This is my app delegates:

  supportedLocales: [
    const Locale('en', 'US'),
    const Locale('ka', 'GE'),
    const Locale('ru', 'RU'),
  ],
  localizationsDelegates: [
    const InfosLocalizationsDelegate(),
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate
  ],
  locale: Locale('ka')

This is Custom LocalizationsDelegate:

class CLocalizationsDelegate
    extends LocalizationsDelegate<CLocalizations> {
  const CLocalizationsDelegate();

  @override
  bool isSupported(Locale locale) =>
      ['en', 'ka', 'ru'].contains(locale.languageCode);

  @override
  Future<CLocalizations> load(Locale locale) async {
    CLocalizations localizations = new CLocalizations(locale);
    await localizations.load();
    print("Load ${locale.languageCode}");
    return localizations;
  }

  @override
  bool shouldReload(CLocalizationsDelegate old) => false;
}

Yeah I know that the problem is 'ka' because MaterialLocalizations doesn't not supports it but I have to solve that problem, so guys can you help me out?

like image 317
Tornike Kurdadze Avatar asked Nov 06 '18 18:11

Tornike Kurdadze


People also ask

How do you add multi language support to your flutter app via dynamic localization?

How do you add multi language support to your Flutter app via dynamic localization? You can add any number of language support by adding . arb files, the process for that is very simple. Just click on Tools > Flutter Intl > Add Locale.

What is localization delegate in flutter?

localizationsDelegates. The delegates for this app's Localizations widget. The delegates collectively define all of the localized resources for this application's Localizations widget.

How do you support multiple languages in flutter?

Create an abstract class which contains all localized strings. We need to define all localized texts in different language string files. Now create other Languages class that support your application and extend Languages class and overrides all strings.


2 Answers

Addig GlobalCupertinoLocalizations too to the localizationsDelegates also saves the problem.

localizationsDelegates: const [
      GlobalMaterialLocalizations.delegate,
      GlobalCupertinoLocalizations.delegate,
      GlobalWidgetsLocalizations.delegate,
    ],
like image 77
Qwadrox Avatar answered Sep 19 '22 07:09

Qwadrox


You can implement your custom MaterialLocalizations delegate

class MaterialLocalizationKaDelegate extends LocalizationsDelegate<MaterialLocalizations> {
  @override
  bool isSupported(Locale locale) {
    return locale.countryCode == "GE" && locale.languageCode == "ka";
  }

  @override
  Future<MaterialLocalizations> load(Locale locale) async {
    return MaterialLocalizationKa();
  }

  @override
  bool shouldReload(Foo old) {
    return false;
  }
}

class MaterialLocalizationKa extends MaterialLocalizations {
  // TODO: implement KA localization yourself
}
like image 27
Rémi Rousselet Avatar answered Sep 19 '22 07:09

Rémi Rousselet