Split user language (UI translation) from locale (formatted values) (#4595)
This commit is contained in:
@@ -24,7 +24,11 @@ use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInt
|
||||
*/
|
||||
final class ThemeOptionsSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
public function __construct(private TokenStorageInterface $storage, private ContextHelper $helper, private LocaleService $localeService)
|
||||
public function __construct(
|
||||
private readonly TokenStorageInterface $storage,
|
||||
private readonly ContextHelper $helper,
|
||||
private readonly LocaleService $localeService
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -44,7 +48,7 @@ final class ThemeOptionsSubscriber implements EventSubscriberInterface
|
||||
|
||||
$this->helper->setAssetVersion((string) Constants::VERSION_ID);
|
||||
|
||||
if ($this->localeService->isRightToLeft(\Locale::getDefault())) {
|
||||
if ($this->localeService->isRightToLeft($event->getRequest()->getLocale())) {
|
||||
$this->helper->setIsRightToLeft(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
namespace App\EventSubscriber;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Twig\LocaleFormatExtensions;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEvent;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
@@ -18,7 +19,11 @@ use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||
|
||||
final class UserEnvironmentSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
public function __construct(private TokenStorageInterface $tokenStorage, private AuthorizationCheckerInterface $auth)
|
||||
public function __construct(
|
||||
private readonly TokenStorageInterface $tokenStorage,
|
||||
private readonly AuthorizationCheckerInterface $auth,
|
||||
private readonly LocaleFormatExtensions $localeFormatExtensions
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -36,19 +41,21 @@ final class UserEnvironmentSubscriber implements EventSubscriberInterface
|
||||
return;
|
||||
}
|
||||
|
||||
// the locale depends on the request, not on the user configuration
|
||||
\Locale::setDefault($event->getRequest()->getLocale());
|
||||
$locale = $event->getRequest()->getLocale();
|
||||
|
||||
// ignore events like the toolbar where we do not have a token
|
||||
if (null === ($token = $this->tokenStorage->getToken())) {
|
||||
return;
|
||||
// events like the toolbar might not have a token
|
||||
if (null !== ($token = $this->tokenStorage->getToken())) {
|
||||
$user = $token->getUser();
|
||||
|
||||
if ($user instanceof User) {
|
||||
$locale = $user->getLocale();
|
||||
date_default_timezone_set($user->getTimezone());
|
||||
$user->initCanSeeAllData($this->auth->isGranted('view_all_data'));
|
||||
}
|
||||
}
|
||||
|
||||
$user = $token->getUser();
|
||||
|
||||
if ($user instanceof User) {
|
||||
date_default_timezone_set($user->getTimezone());
|
||||
$user->initCanSeeAllData($this->auth->isGranted('view_all_data'));
|
||||
}
|
||||
// the locale is primarily used for formatting values, so we depend on the user locale if available
|
||||
\Locale::setDefault($locale);
|
||||
$this->localeFormatExtensions->setLocale($locale);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ use App\Form\Type\InitialViewType;
|
||||
use App\Form\Type\SkinType;
|
||||
use App\Form\Type\TimezoneType;
|
||||
use App\Form\Type\UserLanguageType;
|
||||
use App\Form\Type\UserLocaleType;
|
||||
use App\Form\Type\YesNoType;
|
||||
use Psr\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
@@ -84,11 +85,16 @@ final class UserPreferenceSubscriber implements EventSubscriberInterface
|
||||
->setSection('locale')
|
||||
->setType(TimezoneType::class),
|
||||
|
||||
(new UserPreference(UserPreference::LOCALE, $this->systemConfiguration->getUserDefaultLanguage()))
|
||||
(new UserPreference(UserPreference::LANGUAGE, $this->systemConfiguration->getUserDefaultLanguage()))
|
||||
->setOrder(250)
|
||||
->setSection('locale')
|
||||
->setType(UserLanguageType::class),
|
||||
|
||||
(new UserPreference(UserPreference::LOCALE, $this->systemConfiguration->getUserDefaultLanguage()))
|
||||
->setOrder(250)
|
||||
->setSection('locale')
|
||||
->setType(UserLocaleType::class),
|
||||
|
||||
(new UserPreference(UserPreference::FIRST_WEEKDAY, User::DEFAULT_FIRST_WEEKDAY))
|
||||
->setOrder(300)
|
||||
->setSection('locale')
|
||||
|
||||
Reference in New Issue
Block a user