public function findBestMatchingLocale(Locale $locale)
{
$localeIdentifier = (string) $locale;
if (isset($this->localeCollection[$localeIdentifier])) {
return $this->localeCollection[$localeIdentifier];
}
$parentLocaleIdentifier = $localeIdentifier;
do {
// Remove the last (most specific) part of the locale tag
$parentLocaleIdentifier = substr($parentLocaleIdentifier, 0, (int) strrpos($parentLocaleIdentifier, '_'));
if (isset($this->localeCollection[$parentLocaleIdentifier])) {
return $this->localeCollection[$parentLocaleIdentifier];
}
} while (strrpos($parentLocaleIdentifier, '_') !== false);
return null;
}