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 Jul 2, 2022
1 parent 0fbea2d commit 2c7dc7c
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.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class PKPRequest
/** @var string user agent */
public $_userAgent;


/**
* get the router instance
*
Expand Down Expand Up @@ -883,6 +882,16 @@ public function &_delegateToRouter($method)
$returner = call_user_func_array($callable, $parameters);
return $returner;
}

/**
* 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.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ public function getLocale(): string
$request = $this->_getRequest();
$locale = $request->getUserVar('setLocale')
?: (SessionManager::hasSession() ? SessionManager::getManager()->getUserSession()->getSessionVar('currentLocale') : null)
?: $request->getCookieVar('currentLocale');
?: $request->getCookieVar('currentLocale')
?: $request->getPreferredLanguage($this->_getSupportedLocales());
$this->setLocale($locale);
return $this->locale;
}
Expand Down

0 comments on commit 2c7dc7c

Please sign in to comment.