Skip to content

Commit

Permalink
pkp#10046 Use preferred locale for user full name when passed
Browse files Browse the repository at this point in the history
  • Loading branch information
kaitlinnewson committed Sep 27, 2024
1 parent 27bd806 commit 058e5f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions classes/identity/Identity.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,21 @@ function &getLocalizedData($key, $preferredLocale = null) {
* @param $defaultLocale string
* @return string
*/
function getFullName($preferred = true, $familyFirst = false, $defaultLocale = null) {
$locale = $defaultLocale ?? AppLocale::getLocale();
function getFullName($preferred = true, $familyFirst = false, $defaultLocale = null, $preferredLocale = null) {
$locale = $preferredLocale ?? AppLocale::getLocale();
if ($preferred) {
$preferredPublicName = $this->getPreferredPublicName($locale);
if (!empty($preferredPublicName)) return $preferredPublicName;
}
$givenName = $this->getGivenName($locale);
if (empty($givenName)) {
// Fallback to the site's primary locale if no given name
// exists in the requested locale
$locale = Application::get()->getRequest()->getSite()->getPrimaryLocale();
if (is_null($defaultLocale)) {
// the users register for the site, thus
// the site primary locale is the default locale
$site = Application::get()->getRequest()->getSite();
$defaultLocale = $site->getPrimaryLocale();
}
$locale = $defaultLocale;
$givenName = $this->getGivenName($locale);
}
$familyName = $this->getFamilyName($locale);
Expand Down
4 changes: 2 additions & 2 deletions classes/submission/PKPAuthor.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ function getLocalizedFamilyName() {
/**
* @copydoc Identity::getFullName()
*/
function getFullName($preferred = true, $familyFirst = false, $defaultLocale = null) {
function getFullName($preferred = true, $familyFirst = false, $defaultLocale = null, $preferredLocale = null) {
if (!isset($defaultLocale)) $defaultLocale = $this->getSubmissionLocale();
return parent::getFullName($preferred, $familyFirst, $defaultLocale);
return parent::getFullName($preferred, $familyFirst, $defaultLocale, $preferredLocale);
}

//
Expand Down

0 comments on commit 058e5f4

Please sign in to comment.