0
我已经实施了新的树枝延伸,并且有一些文字需要翻译。Symfony2 +树枝:将标签转换为新的树枝延伸
不幸的是,当我使用code label
它显示为一个示例文本。
我的意思是,当树枝使这个下面的扩展,它显示:5 entity.years
,而不是5 years
例如:
class MyExtension extends \Twig_Extension {
public function getFilters()
{
return array(
'myextension' => new \Twig_Filter_Method($this, 'myextension'),
);
}
public function myextension ($myId)
{
// ....
// Some operations concerning $myId...
// ....
if($myId!=0) {
$res = $myId. ' '.'entity.year';
} else {
$res = ($months == 0 ? $days.'entity.days' : $months.'entity.months');
}
return $res;
}
}
凡entity.years
,entity.months
,entity.days
被定义为我的翻译文件夹中。
谢谢。但我有错误:参数1传递给MySpace \ MyBundle \ Extension \ MyExtension :: __构造()必须是一个实例翻译,没有给出,在'应用程序/缓存/ dev/appDevDebugProjectContainer.php' – Sam 2012-01-03 09:16:04
似乎你忘了[依赖注入](http://symfony.com/doc/current/book/service_container.html#referencing-injecting-services)部分。 – 2012-01-03 09:20:53
我可以加入我的服务: 参数: - 翻译.loader 是什么? – Sam 2012-01-03 09:23:59