O4DOIXmlFilter::getObjectLocalePrecedence PHP Method

getObjectLocalePrecedence() public method

Identify the locale precedence for this export.
public getObjectLocalePrecedence ( $context, $article, $galley ) : array
$context Context
$article PublishedArticle
$galley ArticleGalley
return array A list of valid PKP locales in descending order of priority.
    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;
    }