toLocale method
Parses locale string to Locale. en - will be parse to Locale('en') en_US - will be parsed to Locale('en', 'US') en_US_419 - will be parsed to Locale('en', 'US_419')
Implementation
Locale toLocale() {
if (locale.contains("_")) {
final parts = locale.split("_");
if (parts.length == 1) {
return Locale(parts[0]);
}
if (parts.length == 2) {
return Locale(parts[0], parts[1]);
}
return Locale(parts[0], locale.substring(parts[0].length));
}
return Locale(locale);
}