normalizeLocale method
Normalizes locale
in case it is not fully supported, but a shorter
or specific one might be.
e.g. if this delegate supports 'en_US', 'pt'
:
- Both 'en_US' and 'en' => 'en_US'
- Both 'pt_BR' and 'pt' => 'pt'
Implementation
Locale normalizeLocale(Locale locale) {
if (!locales.contains(locale)) {
locale = locales.firstWhere(
(l) => l.languageCode == locale.languageCode,
orElse: () => throw Exception('Unsupported locale $locale'),
);
}
return locale;
}