Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
General Tech Bugs & Fixes 2 years ago
Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
I'm trying to use symfony sticky locale to change the web locale through the url. For this as is explained y the page y linked before I've created a event subscriber which implements this on onKernelRequest function.
The Event subricreber is running and doing de if($loc) block correctly, but it seems not to be detected by the translator, so it could be a event subcriber priority problem, but I tried to change its priority an still getting same local.
Event Subscriber
php // src/EventSubscriber/LocaleSubscriber.php namespace App\EventSubscriber; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class LocaleSubscriber implements EventSubscriberInterface { private $defaultLocale; public function __construct($defaultLocale = 'en') { $this->defaultLocale = $defaultLocale; } public function onKernelRequest(GetResponseEvent $event) { $request = $event->getRequest(); if (!$request->hasPreviousSession()) { return; } $loc = $request->attributes->get('_locale'); // try to see if the locale has been set as a _locale routing parameter if ($loc) { $request->getSession()->set('_locale', $loc); $request->setLocale($loc); } else { // if no explicit locale has been set on this request, use one from the session $request->setLocale($request->getSession()->get('_locale', $this->defaultLocale)); } } public static function getSubscribedEvents() { return [ // must be registered before (i.e. with a higher priority than) the default Locale listener KernelEvents::REQUEST => [['onKernelRequest', 20]], ]; } }
Controller
/** * @Route("/{_locale}/pro/live") */ public function index(Request $request) { return $this->render('pro/live/index.html.twig'); }
I'm expecting to get change the translator locale to which is writed in the url.
If I change the url to /en/pro/live/ $request->getLocale() in the controller returns the correct locale but the translator local still in es
/en/pro/live/
$request->getLocale()
es
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
General Tech 9 Answers
General Tech 7 Answers
General Tech 3 Answers
General Tech 2 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.