Skip to content

Commit

Permalink
pkp#7512 Added Accept-Language header into the locale detection
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasraoni committed Nov 15, 2024
1 parent abaf70a commit ec846bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 10 additions & 1 deletion classes/core/PKPRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class PKPRequest
/** @var string user agent */
public string $_userAgent;


/**
* get the router instance
*/
Expand Down Expand Up @@ -785,6 +784,16 @@ public function getPublicFilesUrl(?Context $context = null): string
: $publicFileManager->getSiteFilesPath()
]);
}

/**
* Returns the preferred language.
*
* @param string[] $locales An array of ordered available locales
*/
public function getPreferredLanguage(array $locales): ?string
{
return (new \Illuminate\Http\Request(server: $_SERVER))->getPreferredLanguage($locales);
}
}

if (!PKP_STRICT_MODE) {
Expand Down
3 changes: 2 additions & 1 deletion classes/i18n/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ public function getLocale(): string
$request = $this->_getRequest();
$locale = $request->getUserVar('setLocale')
?: $request->getSession()->get('currentLocale')
?: $request->getCookieVar('currentLocale');
?: $request->getCookieVar('currentLocale')
?: $request->getPreferredLanguage($this->_getSupportedLocales());
$this->setLocale($locale);
return $this->locale;
}
Expand Down

0 comments on commit ec846bf

Please sign in to comment.