Doctrine orm symfony2.1可翻译文件已保存,但未检索

Doctrine orm symfony2.1可翻译文件已保存,但未检索,doctrine-orm,symfony-2.1,Doctrine Orm,Symfony 2.1,基本上,我遇到了与这里相同的问题: 保存在ext\u Translations表中但未显示的翻译 在添加建议的修复之后,它确实起了作用 今天我从2.0升级到2.1,到目前为止,我几乎所有的东西都能正常工作 但现在,我的可翻译内容再次无法正确显示(它们仍在正确保存) 我认为这与2.1版与2.0版相比,用户语言环境在何处以及如何存储的变化有关。。但我无法解决这个问题。通过注册自定义侦听器解决了这个问题 namespace XXX; use Symfony\Component\HttpKernel

基本上,我遇到了与这里相同的问题:

保存在
ext\u Translations
表中但未显示的翻译

在添加建议的修复之后,它确实起了作用

今天我从2.0升级到2.1,到目前为止,我几乎所有的东西都能正常工作

但现在,我的可翻译内容再次无法正确显示(它们仍在正确保存)


我认为这与2.1版与2.0版相比,用户语言环境在何处以及如何存储的变化有关。。但我无法解决这个问题。

通过注册自定义侦听器解决了这个问题

namespace XXX;

use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class LocaleListener implements EventSubscriberInterface
{
   private $defaultLocale;

   public function __construct($defaultLocale = 'en')
   {
       $this->defaultLocale = $defaultLocale;
   }

   public function onKernelRequest(GetResponseEvent $event)
   {
       $request = $event->getRequest();
       if (!$request->hasPreviousSession()) {
           return;
       }

       if ($locale = $request->attributes->get('_locale')) {
           $request->getSession()->set('_locale', $request->getLocale());
       } else {
           $request->setDefaultLocale($request->getSession()->get('_locale',             $this->defaultLocale));
       }
   }

   static public function getSubscribedEvents()
   {
       return array(
           // must be registered before the default Locale listener
           KernelEvents::REQUEST => array(array('onKernelRequest', 17)),
       );
   }
}
然后改变

$request->setDefaultLocale($request->getSession()->get('_locale', $this->defaultLocale));

使用

$this->getRequest()->getSession()->set('_locale', 'nl');
要设置区域设置,翻译和可翻译现在可以工作了


希望这对其他人也有帮助

因为我不能回答自己的问题,所以我有答案,但我不能发布:(。。
$this->getRequest()->getSession()->set('_locale', 'nl');