src/Doctrine/Extensions/GlobalHintExtension.php line 34
<?php
// src/Doctrine/Extensions/GlobalHintExtension.php
namespace App\Doctrine\Extensions;
use Doctrine\ORM\EntityManagerInterface;
use Gedmo\Translatable\TranslatableListener;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
#[AsEventListener(event: RequestEvent::class, method: 'onKernelRequest')]
#[AsEventListener(event: ExceptionEvent::class, method: 'onKernelException')]
class GlobalHintExtension
{
private $translatableListener;
public function __construct(TranslatableListener $translatableListener,private readonly RequestStack $requestStack)
{
$this->translatableListener = $translatableListener;
}
public function onKernelRequest(RequestEvent $event)
{
// Enable translation fallback globally
$this->translatableListener->setTranslationFallback(true);
$this->translatableListener->setTranslatableLocale($this->requestStack->getCurrentRequest()->getLocale());
}
public function onKernelException(ExceptionEvent $event)
{
// Handle kernel exception
}
}