symfony 3 - generate current url with different locales
<p>What I want to do is create a language switcher template which outputs a list of links, like so:</p>

<pre><code>&lt;div class="language-switcher"&gt;
    &lt;ul&gt;
        {% for locale in allowed_locales %}
            &lt;li&gt;
                &lt;a href="{{ path($get current route name here $, { '_locale': locale }) }}"&gt;
                    {{ locale|upper }}
                &lt;/a&gt;
            &lt;/li&gt;
        {% endfor %}
    &lt;/ul&gt;
&lt;/div&gt;
</code></pre>

<p>The main problem I'm having is - Twig's built-in <code>path</code> function accepts a route NAME, which there seems to be no way of retrieving in Symfony 3.</p>

<p>The other problem is - the route might have additional parameters, which need to be merged with the _locale parameter. From the code I've found on the internet (all for symfony v2, of course), making this work makes for very ugly code which definitely does not belong in a template.</p>

<p>I think the best way to achieve this is to make a Twig extension with a new route generation function for this purpose, but it seems that might be problematic as well because the path() function is located in another extension, which I don't know how to access from my own extension (and I'm not so sure it's a good idea either).</p>

<p>How could I make this thing?</p>

<p>Edit: I also don't want to pass the data to the template in each action because that's not DRY at all.</p>