Pkp-lib: [OJS] If a title prefix is given for a single locale, it is shown with all article title translations

Created on 2 Jul 2020  路  7Comments  路  Source: pkp/pkp-lib

This applies to all versions of OJS 3, also the latest master branch.

Scenario: a journal publishes articles in Finnish but also gives an English title. The English title has a title prefix defined.

When the Finnish frontend is shown, the English prefix is shown before the Finnish article title.

This is because the title is shown with $publication->getLocalizedTitle() where the prefix is called with $this->getLocalizedData('prefix', $preferredLocale). The getLocalizedData function will always return some value. So you end up with a situation where the title is shown in Finnish but the getLocalizedData function will fetch the English version of the prefix because it is the only value available.

https://github.com/pkp/pkp-lib/blob/master/classes/publication/PKPPublication.inc.php#L97

This works the same in older OJS 3 versions.

The preferred way for this to work would of course be that the prefix is only shown for the locale matching the title.

Bug

All 7 comments

Would a short term solution here be to detect what locale has been returned for the title and only add that prefix?

$prefix = '';
$title = $this->getLocalizedData('title', $preferredLocale);
$allPrefixes = $this->getData('prefix');
$allTitles = $this->getData('title');
foreach ($allTitles as $locale => $localizedTitle) {
    if ($title === $localizedTitle) {
        if (is_array($allPrefixes) && array_key_exists($locale, $allPrefixes)) {
            $prefix = $allPrefixes[$locale];
        }
    }
}
if ($prefix) {
    return $prefix . ' ' . $title;
}
return $title;

This is probably the best we can do. It does have a potential problem if the main title is the same for two languages but the prefix is different or missing from the other language.

Das Experiment
The Experiment

Perhaps what we need is a private method that gets the locale of a particular data property, and then uses that in PKPSubmission::getLocalizedData(). It could be re-used in the methods that concatenate the title so that it always concatenated the correct locale pieces.

Would a short term solution here be to detect what locale has been returned for the title and only add that prefix?

Yes, this is similar logic to what we've used for getting full author/user names. See lib/pkp/classes/identity/Identity.inc.php in the getFullName function for the logic. Long story short, pick a "most important" piece of data (the title in the case of submission titles, and the given name in the case of names) and attach other content (family names, subtitles, prefixes) only when it agrees with the locale of that most important data.

PRs:

@NateWr, could you take a quick look?

Merged -- thanks! (@NateWr, I don't think I got a 100% good-to-go on the code review, but I did address the two questions -- please let me know if I moved too quick!)

(Also cherry-picked to stable-3_2_1)

Was this page helpful?
0 / 5 - 0 ratings