Zend Framework 2 - Doctrine 2,Translate annotated ObjectSelect strings

时间:2014-05-17 01:21:14

标签: doctrine-orm annotations zend-framework2 translation

我的doctrine 2实体工作正常,但实体字段是ObjectSelect(DoctrineModule \ Form \ Element \ ObjectSelect),其 empty_option 参数设置为 安全问题

问题是我无法将安全问题字符串添加到我的模块.po翻译文件中,因此我无法翻译该字符串。如果我手动将该字符串添加到.po文件中,那么,当我将.po文件与PoEdit同步时,它会被删除,因为它不包含在translate()方法中

任何人都知道如何让该字符串与PoEdit同步?

谢谢!

PS:这是我的$ question字段的完整注释

/**
 * @var CsnUser\Entity\Question
 *
 * @ORM\ManyToOne(targetEntity="CsnUser\Entity\Question")
 * @ORM\JoinColumn(name="question_id", referencedColumnName="id", nullable=false)
 * @Annotation\Type("DoctrineModule\Form\Element\ObjectSelect")
 * @Annotation\Filter({"name":"StripTags"})
 * @Annotation\Filter({"name":"StringTrim"})
 * @Annotation\Validator({"name":"Digits"})
 * @Annotation\Required(true)
 * @Annotation\Options({
 *   "required":"true",
 *   "empty_option": "Security question",
 *   "target_class":"CsnUser\Entity\Question",
 *   "property": "question"
 * })
 */
protected $question;

1 个答案:

答案 0 :(得分:2)

这个是相当讨厌但有效。只需将要翻译的字符串添加到您的实体构造中即可。

public function __construct()
{
....
   translate('Security question');
....
}

我通常仍会建议使用注释,而使用this应该可以让您完全控制自己需要的表单。