Skip to content

Instantly share code, notes, and snippets.

@migmolrod
Created September 1, 2015 02:23
Show Gist options
  • Save migmolrod/63be83ccbaf2a0db3fa4 to your computer and use it in GitHub Desktop.
Save migmolrod/63be83ccbaf2a0db3fa4 to your computer and use it in GitHub Desktop.
Adding a translatable language switcher to JMSI18nRoutingBundle
parameters:
locale: 'es_ES'
locales: [ 'de', 'en_GB', 'es_ES', 'fr' ]
jms_i18n_routing:
default_locale: %locale%
locales: %locales%
twig:
globals:
lang:
locale: %locale%
locales: %locales%
<ul>
{% for locale in lang.locales %}
{% set current = (app.request.locale == locale) %}
<li>
<a href="{{ path(app.request.get('_route'), app.request.get('_route_params')|merge({'_locale': locale})) }}">
{{ locale|trans({}, 'lang', locale) }}
{{ current ? '✓' : '' }}
</a>
</li>
{% endfor %}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment