简体   繁体   中英

Translation doesn't work with Anonymous user at symfony2

I have symfony 2.3 and I configured the translation for i18n purpose, putting the _locale in url, and it works well for authenticated users but not for anonymous user, for the anonymous user always give me the default locale, at the profiler the locale appears well but It don't load the proper translation.

Pd: I'm using FOSUserBundle

Please make sure the session has been started for the anonymous user. in your controller check with:

$this->container->get('session')->isStarted()

start session

$this->container->get('session')->start();

If the session is started correctly, verify the locale has been set.

using $this->get() alias for $this->container->get() in further examples.

get the locale

$this->get('session')->get('_locale');

otherwise set the locale

$this->get('session')->set('_locale', 'en_US');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM