flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.28k stars 27.52k forks source link

Locale.toString() is not released for non-debugging use #83170

Open tiloc opened 3 years ago

tiloc commented 3 years ago

According to the documentation, Locale.toString() is only to be used for debugging: https://api.flutter.dev/flutter/dart-ui/Locale/toString.html

The proposed alternative is toLanguageTag().

However, toString uses underscores, whereas toLanguageTag uses hyphens as separators.

The popular Dart 'intl' library requires stringified locales with underscores, as returned by toString.

I am therefore proposing that either toString() becomes officially usable for non-debugging production use. Or the toLanguageTag method gains a 'separator' parameter which defaults to '-'.

goderbauer commented 3 years ago

What API in the intl library requires this format?

tiloc commented 3 years ago

@goderbauer Numerous, such as the constructor for NumberFormatter: https://pub.dev/packages/intl#number-formatting-and-parsing

var f = NumberFormat('###.0#', 'en_US');
print(f.format(12.345));
  ==> 12.34

or DateFormat:

DateFormat.yMd('en_US').parse('1/10/2012');
DateFormat('Hms', 'en_US').parse('14:23:01');

or setting the global locale:

Intl.defaultLocale = 'pt_BR';

All these examples taken from their examples page.