getSimilarLocales function

List<String> getSimilarLocales(
  1. String locale
)

Returns a similar locale, usually for fallback discover.

Implementation

List<String> getSimilarLocales(String locale) {
  var canonicalizedLocale = Intl.canonicalizedLocale(locale);

  var shortLocale = Intl.shortLocale(canonicalizedLocale);

  var list = _allLocales.keys
      .where((l) => l == shortLocale || l.startsWith('${shortLocale}_'))
      .toList(growable: true);

  return list;
}