I run a multi-language Symfony 4.4 website where the locale is part of the URL. So I have /it/
, /fr/
and so on.
My routes look like this:
/**
* @Route({
* "it": "/it/azienda/",
* "es": "/es/empresa/"
* }, name="app_cms_about")
*/
Then I've a pre-controller event that set the correct locale:
public function onRouteRequest(ControllerEvent $event)
{
// ... checks and stuff ...
$event->getRequest()->setLocale($ln);
}
Everything works as expected via web, but now I need to manage this language difference in a CLI Command: basically it means that when I run $this->urlGenerator->generate('app_cms_about')
from the CLI, I expect to get the locale-based URL.
The user must pass the locale to the CLI Command to as an argument:
protected function configure()
{
$this->addArgument(
"app_language",
InputArgument::REQUIRED,
'The site to run on: `it`, `es`, ...');
}
Now I just need to set this somehow. I'd love to it with an event, but of course there is no getRequest()
on the CLI event to set the locale on.
How do I set the locale on a Symfony 4 CLI Command?