function getObjectLocalePrecedence($context, $article, $galley)
{
$locales = array();
if (is_a($galley, 'ArticleGalley') && AppLocale::isLocaleValid($galley->getLocale())) {
$locales[] = $galley->getLocale();
}
if (is_a($article, 'Submission')) {
// First try to translate the article language into a locale.
$articleLocale = $this->translateLanguageToLocale($article->getLanguage());
if (!is_null($articleLocale)) {
$locales[] = $articleLocale;
}
// Use the article locale as fallback only
// as this is the primary locale of article meta-data, not
// necessarily of the article itself.
if (AppLocale::isLocaleValid($article->getLocale())) {
$locales[] = $article->getLocale();
}
}
// Use the journal locale as fallback.
$locales[] = $context->getPrimaryLocale();
// Use form locales as fallback.
$formLocales = array_keys($context->getSupportedFormLocaleNames());
// Sort form locales alphabetically so that
// we get a well-defined order.
sort($formLocales);
foreach ($formLocales as $formLocale) {
if (!in_array($formLocale, $locales)) {
$locales[] = $formLocale;
}
}
assert(!empty($locales));
return $locales;
}