Unhandled Exception: Invalid argument(s): Invalid locale "yue_Hant_HK"
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)
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.
The same exception occurs when the locale is “ars_EG” and "gd_GB". I will place the error log so that it can be found in a Google search.
ArgumentError: Invalid argument(s): Invalid locale "ars_EG"
#0 _throwLocaleError (package:intl/src/intl_helpers.dart:208)
#1 verifiedLocale (package:intl/src/intl_helpers.dart:202)
#2 verifiedLocale (package:intl/src/intl_helpers.dart:182)
#3 new DateFormat (package:intl/src/intl/date_format.dart:267)
#4 new DateFormat.E (package:intl/src/intl/date_format.dart:527)
ArgumentError: Invalid argument(s): Invalid locale "gd_GB"
#0 _throwLocaleError (package:intl/src/intl_helpers.dart:208)
#1 verifiedLocale (package:intl/src/intl_helpers.dart:202)
#2 verifiedLocale (package:intl/src/intl_helpers.dart:182)
#3 new DateFormat (package:intl/src/intl/date_format.dart:267)
#4 new DateFormat.EEEE (package:intl/src/intl/date_format.dart:528)
The same exception occurs when the locale is “yue_Hant_GB” in iOS 18.2.1 and 18.3. intl version: 0.19.0
Invalid argument(s): Invalid locale "yue_Hant_GB", #0 _throwLocaleError (package:intl/src/intl_helpers.dart:208) #1 verifiedLocale (package:intl/src/intl_helpers.dart:202) #2 new DateFormat (package:intl/src/intl/date_format.dart:267)
iOS problem only right?
@GianpaoloPascasi Yes, it only happens in iOS.
This is not a platform specific issue, concerns all platforms. Sample crash from Android 13:
Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: Invalid argument(s): Invalid locale "so_SO". Error thrown Failed with locale: so_SO.
at ._throwLocaleError(intl_helpers.dart:208)
at .verifiedLocale(intl_helpers.dart:202)
at .new _CompactNumberFormat(compact_number_format.dart:269)
at new NumberFormat.compactSimpleCurrency(number_format.dart:445)