parseLocaleParts method
Finds the locale type E which fits the locale parts the best.
Fallbacks to base locale.
Implementation
E parseLocaleParts({
required String languageCode,
String? scriptCode,
String? countryCode,
}) {
E? selected;
// match exactly
selected = locales.firstWhereOrNull((supported) =>
supported.languageCode == languageCode &&
supported.scriptCode == scriptCode &&
supported.countryCode == countryCode);
if (selected == null) {
// match language
selected = locales.firstWhereOrNull((supported) {
return supported.languageCode == languageCode;
});
}
if (selected == null && countryCode != null) {
// match country
selected = locales.firstWhereOrNull((supported) {
return supported.countryCode == countryCode;
});
}
return selected ?? baseLocale;
}