在我的Symfony 2.8项目中,我有一个扩展,它向trans方法添加了一些额外的逻辑:
parameters:
translator.class: MyBundle\Twig\TranslationExtension
这个类看起来像这样:
namespace MyBundle\Twig\TranslationExtension;
use Symfony\Bundle\FrameworkBundle\Translation\Translator as BaseTranslator;
class TranslationExtension extends BaseTranslator
{
private $currentLocale;
public function trans($id, array $parameters = array(), $domain = null, $locale = null)
{
$translation = parent::trans($id, $parameters, $domain, $locale);
// Some extra logic here
return $translation;
}
public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null)
{
return parent::transChoice($id, $number, $parameters, $domain, $locale);
}
}
现在,我正在迁移到Symfony 3,其中那些类参数已被弃用,但是我如何通过覆盖translator服务来实现这一点呢?