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')
);

```
```
class BaseCommand extends ContainerAwareCommand
{
    protected function getLocale()
    {
        return $this->getContainer()->get('translator')->getLocale();
    }

    protected function render($view, $data)
    {
        return $this->getContainer()->get('templating')->render($view, $data);
    }
}  

```

in command 

```
class SomeCommand extends BaseCommand
{
    ...
    $this->render($view, array_merge($data, ['_locale' => $this->getLocale()])
}

```

in view 

```
{{url('any', {param: 'foo'}|merge(_locale is defined ? {'_locale': _locale } : {}))}}

```