[UTIL][Common] Respect detect language setting

Minor bug fix
This commit is contained in:
Diogo Peralta Cordeiro 2022-03-09 01:30:13 +00:00
parent d857baa0f1
commit 893d299e29
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
2 changed files with 14 additions and 2 deletions

View File

@ -547,7 +547,7 @@ class Actor extends Entity
if (\defined($const)) { if (\defined($const)) {
return $this->type === \constant($const); return $this->type === \constant($const);
} else { } else {
throw new BugFoundException("Actor cannot be a '{$type}', check your spelling"); throw new BugFoundException("Actor cannot be a '{$type}', check your spelling.");
} }
} else { } else {
return parent::__call($name, $arguments); return parent::__call($name, $arguments);

View File

@ -328,6 +328,18 @@ abstract class Common
public static function currentLanguage(): Language public static function currentLanguage(): Language
{ {
return self::actor()?->getTopLanguage() ?? Language::getByLocale(self::$request->headers->has('accept-language') ? I18n::clientPreferredLanguage(self::$request->headers->get('accept-language')) : self::config('site', 'language')); // Prefer the Actor's language, if set.
$language = self::actor()?->getTopLanguage();
if (!\is_null($language)) {
return $language;
}
if (
self::config('site', 'detect_language')
&& !\is_null(self::$request?->headers)
&& self::$request->headers->has('accept-language')
) {
return Language::getByLocale(I18n::clientPreferredLanguage(self::$request->headers->get('accept-language')));
}
return Language::getByLocale(self::config('site', 'language'));
} }
} }