{% set route_params = app.request.attributes.get('_route_params') %}
{# merge the query string params to keep them when switching the locale #}
{% if route_params %}
{% set route_params = route_params|merge(app.request.query.all) %}
{% endif %}
{# |filter() crashes if the array is empty #}
{% if route_params is not empty %}
{# remove unnecessary parameters #}
{% set route_params = route_params|filter((v, k) => k not in ['_locale', 'template']) %}
{% endif %}
<ul>
{% for country, domain in country_list() %}
<li>
{% if is_current_country(country) %}
<span class="fleche01">
<span class="fleche">
<span class="ligne1"></span>
<span class="ligne2"></span>
</span>
</span>
{% else %}
<span class="fleche01"><span class="fleche"></span></span>
{% endif %}
<a href="{{ path('frontend_redirect_to_country', {
'country': country,
'route' : app.request.get('_route') ? app.request.get('_route') : 'homepage',
'params': route_params}) }}">
<i class="icon-flag-{{ country }}"></i>
{{ ('frontend.country.'~country)|trans }}
</a>
</li>
{% endfor %}
</ul>