toLocale method
Convert string to Locale object
Implementation
Locale toLocale({String separator = '_'}) {
final localeList = split(separator);
switch (localeList.length) {
case 2:
return localeList.last.length == 4 // scriptCode length is 4
? Locale.fromSubtags(
languageCode: localeList.first,
scriptCode: localeList.last,
)
: Locale(localeList.first, localeList.last);
case 3:
return Locale.fromSubtags(
languageCode: localeList.first,
scriptCode: localeList[1],
countryCode: localeList.last,
);
default:
return Locale(localeList.first);
}
}