[UTIL][Common][I18N] Use actor's preferred language for _m and utility to retrieve current language even when no actor is logged in
This commit is contained in:
parent
6247dd4c1a
commit
5a0bbfc795
|
@ -49,7 +49,7 @@ class Feeds extends FeedController
|
|||
{
|
||||
$data = $this->query(
|
||||
query: 'note-local:true',
|
||||
language: Common::actor()?->getTopLanguage()?->getLocale(),
|
||||
locale: Common::currentLanguage()->getLocale(),
|
||||
);
|
||||
return [
|
||||
'_template' => 'collection/notes.html.twig',
|
||||
|
@ -67,7 +67,7 @@ class Feeds extends FeedController
|
|||
$actor = $user->getActor();
|
||||
$data = $this->query(
|
||||
query: 'note-from:subscribed-person,subscribed-group,subscribed-organization,subscribed-business',
|
||||
language: $actor->getTopLanguage()->getLocale(),
|
||||
locale: Common::currentLanguage()->getLocale(),
|
||||
actor: $actor,
|
||||
);
|
||||
return [
|
||||
|
|
|
@ -53,7 +53,7 @@ class Feeds extends FeedController
|
|||
Common::ensureLoggedIn();
|
||||
$data = $this->query(
|
||||
query: 'note-local:false',
|
||||
language: Common::actor()?->getTopLanguage()?->getLocale(),
|
||||
locale: Common::currentLanguage()->getLocale(),
|
||||
);
|
||||
return [
|
||||
'_template' => 'collection/notes.html.twig',
|
||||
|
@ -101,7 +101,7 @@ class Feeds extends FeedController
|
|||
Common::ensureLoggedIn();
|
||||
$data = $this->query(
|
||||
query: '',
|
||||
language: Common::actor()?->getTopLanguage()?->getLocale(),
|
||||
locale: Common::currentLanguage()->getLocale(),
|
||||
);
|
||||
return [
|
||||
'_template' => 'collection/notes.html.twig',
|
||||
|
|
|
@ -38,6 +38,7 @@ declare(strict_types = 1);
|
|||
|
||||
namespace App\Core\I18n;
|
||||
|
||||
use App\Util\Common;
|
||||
use App\Util\Exception\ServerException;
|
||||
use App\Util\Formatting;
|
||||
use InvalidArgumentException;
|
||||
|
@ -319,7 +320,7 @@ function _m(...$args): string
|
|||
switch (\count($args)) {
|
||||
case 1:
|
||||
// Empty parameters, simple message
|
||||
return I18n::$translator->trans($args[0], [], $domain);
|
||||
return I18n::$translator->trans($args[0], [], $domain, Common::currentLanguage()->getLocale());
|
||||
case 3:
|
||||
// @codeCoverageIgnoreStart
|
||||
if (\is_int($args[2])) {
|
||||
|
@ -337,7 +338,7 @@ function _m(...$args): string
|
|||
if (\is_string($args[0])) {
|
||||
$msg = $args[0];
|
||||
$params = $args[1] ?? [];
|
||||
return I18n::$translator->trans($msg, $params, $domain);
|
||||
return I18n::$translator->trans($msg, $params, $domain, Common::currentLanguage()->getLocale());
|
||||
}
|
||||
// Fallthrough
|
||||
// no break
|
||||
|
|
|
@ -34,11 +34,13 @@ declare(strict_types = 1);
|
|||
|
||||
namespace App\Util;
|
||||
|
||||
use App\Core\I18n\I18n;
|
||||
use App\Core\Router\Router;
|
||||
use App\Core\Security;
|
||||
use App\Entity\Actor;
|
||||
use App\Entity\LocalUser;
|
||||
use App\Util\Exception\NoLoggedInUser;
|
||||
use Component\Language\Entity\Language;
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
use Egulias\EmailValidator\Validation\RFCValidation as RFCEmailValidation;
|
||||
use Functional as F;
|
||||
|
@ -318,4 +320,9 @@ abstract class Common
|
|||
}
|
||||
return $notes;
|
||||
}
|
||||
|
||||
public static function currentLanguage(): Language
|
||||
{
|
||||
return self::actor()?->getTopLanguage() ?? Language::getByLocale(!\is_null(self::$request->headers->get('accept-language')) ? I18n::clientPreferredLanguage(self::$request->headers->get('accept-language')) : self::$request->getDefaultLocale());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user