normalizeLocale method

Locale normalizeLocale (
  1. Locale locale
)

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 (!supported.contains(locale))
    locale = supported.firstWhere(
      (l) => l.languageCode == locale.languageCode,
      orElse: () => throw Exception('Unsupported locale $locale'),
    );
  return locale;
}