Open louislamlam opened 11 months ago
Same crash e.g. with "sco_AU" and "nap_IT".
Could you please provide a function like "isLocaleSupported" to avoid these unnecessary crashes. We could then fall back to some default locale on app startup if needed.
I do this on app startup currently:
Locale locale = WidgetsBinding.instance.platformDispatcher.locale;
Intl.systemLocale = locale.toString();
// workaround to https://github.com/dart-lang/intl/issues/280
Intl.defaultLocale ??= Intl.systemLocale;
And would like to change it to something like:
Locale locale = WidgetsBinding.instance.platformDispatcher.locale;
// Check if the locale is supported, otherwise use a fallback
if (!Intl.isLocaleSupported(locale)) {
locale = Locale('en', 'US'); // Fallback locale
}
Intl.systemLocale = locale.toString();
// workaround to https://github.com/dart-lang/intl/issues/280
Intl.defaultLocale ??= Intl.systemLocale;
Additionally to missing supportedLocales
, package:intl
also doesn't have great fallback logic. If it's any help, both of these features are present in the experimental package:intl4x
.
Which locale is missing? yue_Hant_HK
Which locale have you considered of using instead, but was not sufficient? Nothing
Error appears when try calling
NumberFormat.compact()
in iOS 17`[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s): Invalid locale "yue_Hant_HK"
0 _throwLocaleError (package:intl/src/intl_helpers.dart:204:3)
1 verifiedLocale (package:intl/src/intl_helpers.dart:198:42)
2 verifiedLocale (package:intl/src/intl_helpers.dart:183:12)
3 new DateFormat (package:intl/src/intl/date_format.dart:267:27)`