diff --git a/classes/core/PKPRequest.php b/classes/core/PKPRequest.php index 569de09117f..6c588ff0dee 100644 --- a/classes/core/PKPRequest.php +++ b/classes/core/PKPRequest.php @@ -65,7 +65,6 @@ class PKPRequest /** @var string user agent */ public string $_userAgent; - /** * get the router instance */ @@ -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) { diff --git a/classes/i18n/Locale.php b/classes/i18n/Locale.php index 9037d97b32b..cc88cd62397 100644 --- a/classes/i18n/Locale.php +++ b/classes/i18n/Locale.php @@ -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; }