toLocale static method

Locale? toLocale(
  1. String? _locale
)

Return a Locale object from the provided String

Implementation

static Locale? toLocale(String? _locale) {
  Locale? locale;

  if (_locale != null && _locale.isNotEmpty) {
    //
    var localeCode = _locale.split('_');
    if (localeCode.length == 1) {
      // Possibly it's in a language tag format
      localeCode = _locale.split('-');
    }
    String languageCode;
    String? countryCode;
    if (localeCode.length == 2) {
      languageCode = localeCode.first;
      countryCode = localeCode.last;
    } else {
      languageCode = localeCode.first;
    }
    locale = Locale(languageCode, countryCode);
  }
  return locale;
}