i18n icon indicating copy to clipboard operation
i18n copied to clipboard

Unhandled Exception: Invalid argument(s): Invalid locale "yue_Hant_HK"

Open louislamlam opened this issue 2 years ago • 7 comments

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)

louislamlam avatar Nov 29 '23 17:11 louislamlam

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;

kinex avatar Sep 30 '24 08:09 kinex

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.

mosuem avatar Sep 30 '24 12:09 mosuem

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)

yamashita-room-335 avatar Jan 24 '25 16:01 yamashita-room-335

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)

LYFhub avatar Jan 25 '25 09:01 LYFhub

iOS problem only right?

GianpaoloPascasi avatar Feb 27 '25 16:02 GianpaoloPascasi

@GianpaoloPascasi Yes, it only happens in iOS.

louislamlam avatar Mar 28 '25 18:03 louislamlam

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)

kinex avatar Apr 01 '25 07:04 kinex