getLocaleFromTag function
Implementation
Locale getLocaleFromTag(String localeTag) {
var languageParts = RegExp(r'([a-z]*)[_-]?([a-z]*)').firstMatch(localeTag);
var languageCode = languageParts?.group(1);
var countryCode = languageParts?.group(2);
if (languageCode == null) {
throw StateError("Can't parse locale tag '$localeTag'");
}
return Locale(languageCode, countryCode);
}