Symfony2 get route name without locale prefix

640 views Asked by At

I am trying to translate my website with JMSTtranslationBundle and Symfony2.7.

I am trying to make a language switcher. So i need to get the current route name and create new routes with it for other languages.

{% set route_params = app.request.attributes.get('_route_params') %}
{% set route_params = route_params|merge(app.request.query.all) %}
<ul>
    {% for culture in cultures %}
        {% set route_params = route_params|merge({'_locale': culture.id}) %}
        <li>
            <a href="{{ path(app.request.attributes.get('_route'), route_params) }}">
                {{ culture.name }}
            </a>
        </li>
    {% endfor %}
</ul>

The app.request.attributes.get('_route') should return the route name like 'homepage', but it return the route prefix by locale like 'en__RG__homepage'.

Because of this, the route created for each language is the same that the current.

It is possible to get the route name without this prefix?


EDIT

For example, my homepage route definition is :

homepage:
    pattern:  /
    defaults: { _controller: APPBundle:Default:index }

And in my jms config:

jms_i18n_routing:
    default_locale: en
    locales: [en, fr]
    strategy: prefix_except_default

So, routes are translate in routes.en.xliff and routes.fr.xliff

0

There are 0 answers