Question: I have a problem with the symfony routing.

For an multilanguage projekt I render a Twig template via a job queue for mailing. In this template is a link to a route that requires the "\_locale" parameter with "de" or "en" for example. I use the function "{{ url('route', {'\_locale': 'de'}) }}" to generate the url.

By rendering the template, I got the following error message:

```
[Twig_Error_Runtime]
An exception has been thrown during the rendering of a template ("Some mandatory parameters are missing ("_locale") to generate a URL for route "Route".") in "TemplatePath" at line 5. 

```

Whats my mistake?

Thanks for help

Answer: 
When you are generating URL route, via CLI, the Symfony kernel is missing a HTTP `Request`, and a `Routing->RequestContext`.

Thats why, the URL generator cannot find `_locale` parameter.

To fix it, you must manually create a `RequestContext`, so, in your command:

```
$this->getContainer()->get('router')
->setContext(
   (new RequestContext())
   ->setParameter('_locale', 'fr')
);

```
It's necro time :)
I'm just guessing here, but there's a couple things you can try.

**Can you set the locale in your command?**

Set the locale for the translator bundle:

```
$this->getContainer()->get('translator')->setLocale('de');

```

Set the locale for this session:

```
$this->getContainer()->get('session')->setLocale('de);

```

**Internationalized routing for Symfony 4.1 and higher**

If this applies to you, try this:

```
url('route.de', {'_locale': 'de'}) }}"

```

**Does your route have 'de' and 'en' set as a requirement?**

```
/**
 * Matches /route
 * @Route(
 *     "/route/{_locale}",
 *     requirements={
 *         '_locale': 'en|de'
 *     },
 *     name="route"
 * )
 */

```

It's an old question but this might help someone out.