关闭转换器缓存

时间:2011-11-23 03:12:20

标签: symfony caching localization

我正试图通过这种方式关闭翻译缓存:

应用程序/配置/ config.yml

    services:
        translator.default:
            class:  %translator.class%
            arguments: [ @service_container, @translator.selector, {}, { cache_dir: null, debug: %kernel.debug% }, @?session ]

cache / dev / appDevDebugProjectContainer.php中的缓存代码应为:


    protected function getTranslator_DefaultService()
    {
        $this->services['translator.default'] = $instance = new \Symfony\Bundle\FrameworkBundle\Translation\Translator($this, new \Symfony\Component\Translation\MessageSelector(), array('translation.loader.php' => 'php', 'translation.loader.yml' => 'yml', 'translation.loader.xliff' => 'xliff'), array('cache_dir' => NULL, 'debug' => true), $this->get('session'));

        ... resources ...

        return $instance;
    }

但是我得到了代码:


    protected function getTranslator_DefaultService()
    {
        return $this->services['translator.default'] = new \Symfony\Bundle\FrameworkBundle\Translation\Translator($this, new \Symfony\Component\Translation\MessageSelector(), array('translation.loader.db' => 'db', 'translation.loader.php' => 'php', 'translation.loader.yml' => 'yml', 'translation.loader.xliff' => 'xliff'), array('cache_dir' => NULL, 'debug' => true), $this->get('session'));
    }

所以翻译资源是空的。

1 个答案:

答案 0 :(得分:-6)

一种方法是:

修改symfony/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php并添加方法:

public function setOption($option, $value)
{
    $this->options[$option] = $value;
}

AppKernel.php覆盖方法:

public function boot()
{
    parent::boot();
    $this->container->get('translator')->setOption('cache_dir', null);
}