How do I get the locale in a Symfony 2.1 controller?
I have installed a package https://github.com/lunetics/LocaleBundle which allows switching between languages. Everything works fine, in tweeted, translation works fine. But when I want to translate any message into a controller, I get French (fr) instead of a specific language (like en).
How can I get the currently selected locale in the controller?
i use: $this->getRequest()->getLocale()
but it doesn't work, it gives me FR for each culture.
my default install language in the .ini parameter is FR
source to share
After looking at the LuneticsLocaleBundle and Symfony 2.1 code, I found that symfony2.1 passes the Locale into the route. The problem occurs when rendering an activity from a twig template where symfony creates a nes request. So, to solve this problem, I am overriding the LuneticsLocaleBundle code, and I added $this->get('session')->set('_locale', $_locale);
to switchAction from the LocaleController of the bundle.
So, the locale will be saved in the session.
I hope this helps too.
source to share