1

I'm trying to make my Flutter app use multiple languages, and especially Calendar (Material Date Picker). It should work like this: if the device’s first language is available in the App, use it language in the App. As Android could have a list of user languages in Settings, it should look if the next language available in the App and so on. If there are no such languages, use English as default. On my Android Emulator I now have two languages (Polish and German).

enter image description here

In my App I only have English, German and Italian. As my App doesn’t have Polish, my native Material Date Picker should be in German (because it’s the next available language that my App supports). Unfortunately its only partially the case.

The part above (Fr., 9. Dez.) is in German. The part below is in Polish. I need it to be completely in German in this case.

enter image description here

My pubspec.yaml file:

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  intl: ^0.17.0
flutter:
  uses-material-design: true

My locales_config.xml:

<?xml version="1.0" encoding="utf-8"?>
<locale-config xmlns:android="http://schemas.android.com/apk/res/android">
   <locale android:name="en"/>
   <locale android:name="de"/>
   <locale android:name="it"/>
</locale-config>

My build.gradle:

defaultConfig {
 resConfigs ("en", "de", "it")
}

My main.dart:

class App extends StatelessWidget {
  const App({Key? key}) : super(key: key);

  static const supportedLanguages = [
    Locale('en', 'US'),
    Locale('de', 'DE'),
    Locale('it‘, 'IT'),
  ];

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      localizationsDelegates: const [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: supportedLanguages,
      localeListResolutionCallback: ((locales, supportedLocales) {
        for (Locale locale in locales!) {
          // if device language is supported by the app,
          // just return it to set it as current app language
          if (supportedLocales.contains(locale)) {
            return locale;
          }
        }
        return const Locale('en', 'US');
      }),
      home: BlocProvider(
        create: (BuildContext context) => sl<WebviewBloc>(),
        child: const Root(),
      ),
    );
  }
}

All the logs are showing that the app is running in German as it should be. But the Calendar is partly in German and partly in Polish.

Anna R.
  • 81
  • 12

0 Answers0