diff --git a/lib/locale.dart b/lib/locale.dart index ad16741bcc..65b9e3659f 100644 --- a/lib/locale.dart +++ b/lib/locale.dart @@ -16,14 +16,25 @@ const List appSupportedLocales = [ ]; Locale localResolutionCallBack(locales, supportedLocales) { - // print call stacktrace to identify caller + Locale? languageCodeMatch; + final Map languageCodeToLocale = { + for (Locale supportedLocale in appSupportedLocales) + supportedLocale.languageCode: supportedLocale + }; + for (Locale locale in locales) { if (appSupportedLocales.contains(locale)) { return locale; } + + if (languageCodeMatch == null && + languageCodeToLocale.containsKey(locale.languageCode)) { + languageCodeMatch = languageCodeToLocale[locale.languageCode]; + } } - // if device language is not supported by the app, use en as default - return const Locale('en'); + + // Return the first language code match or default to 'en' + return languageCodeMatch ?? const Locale('en'); } Future getLocale() async {