schmittjoh / JMSI18nRoutingBundle

Allows you to internationalize your routing
http://jmsyst.com/bundles/JMSI18nRoutingBundle
358 stars 159 forks source link

Creating a Language Switcher #190

Open lchabrand opened 8 years ago

lchabrand commented 8 years ago

Hi, first thank you for your bundle which seems very nice. You leave the part "Creating a Language Switcher" empty, can you please explain how to change a language switcher ? Regards,

CharlyPoppins commented 8 years ago

One way to do this :

<a href="{{ path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')|merge({'_locale' : 'fr'})) }}">FR</a> 
<a href="{{ path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')|merge({'_locale' : 'en'})) }}">EN</a>
antondemanov commented 8 years ago

I made it like this (Twig template):

{% for lang in ['en', 'ru', 'de', 'es', 'fr', 'pt', 'it'] if lang != app.request.locale %}
    <a href="{{ path(app.request.attributes.get('_route', 'home'), app.request.attributes.get('_route_params', {})|merge({ _locale: lang })) }}">
        <span>{{ lang|title }}</span>
    </a>
{% endfor %}
aik099 commented 7 years ago

The http://jmsyst.com/bundles/JMSI18nRoutingBundle/master/cookbook/language_switcher page is still empty.