function getPrimaryTranslation($localizedData, $localePrecedence)
{
// Check whether we have localized data at all.
if (!is_array($localizedData) || empty($localizedData)) {
return null;
}
// Try all locales from the precedence list first.
foreach ($localePrecedence as $locale) {
if (isset($localizedData[$locale]) && !empty($localizedData[$locale])) {
return $localizedData[$locale];
}
}
// As a fallback: use any translation by alphabetical
// order of locales.
ksort($localizedData);
foreach ($localizedData as $locale => $value) {
if (!empty($value)) {
return $value;
}
}
// If we found nothing (how that?) return null.
return null;
}