verifiedLocale function
Implementation
String? verifiedLocale(String? newLocale, bool Function(String) localeExists,
String? Function(String)? onFailure) {
// TODO(alanknight): Previously we kept a single verified locale on the Intl
// object, but with different verification for different uses, that's more
// difficult. As a result, we call this more often. Consider keeping
// verified locales for each purpose if it turns out to be a performance
// issue.
if (newLocale == null) {
return verifiedLocale(
global_state.getCurrentLocale(), localeExists, onFailure);
}
if (localeExists(newLocale)) {
return newLocale;
}
for (var each in [
helpers.canonicalizedLocale(newLocale),
helpers.shortLocale(newLocale),
'fallback'
]) {
if (localeExists(each)) {
return each;
}
}
return (onFailure ?? _throwLocaleError)(newLocale);
}