Search code examples
phproutestranslationlocalesymfony

Symfony2 locale in route


I followed Symfony2 doc http://symfony.com/doc/2.0/book/translation.html#the-locale-and-the-url and added locale to my routes. But, I can't find the way to carry locale through routes as I place {{ path('myroute') }} in twig template, but locale always gets fallback value instead taking current locale.

I tried {{ path('myroute', {'_locale': _locale}) }} but I got error "Variable "_locale" does not exist".

Any idea?


Solution

  • Fixed with {{ path('address', {'_locale': app.request.attributes.get('_locale')}) }} thanks to this thread http://www.mail-archive.com/[email protected]/msg34838.html.