我正在使用 JMS Translation Bundle 来提取我的翻译。一切正常,但是当我尝试从表单构建器中提取翻译消息时,我收到以下消息:
[JMS\TranslationBundle\Exception\RuntimeException]
Unable to extract translation id for form label from non-string values, but got "PHPParser_Node_Expr_MethodCall" in /srv/local.project.com/app/../src/Project/MyBundleBundle/Form/Type/EmailType
.php on line 30. Please refactor your code to pass a string, or add "/** @Ignore */".
我使用的代码如下:
public function __construct($translator)
{
//translation service passed from controller
$this->trans = $translator;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('email', 'repeated', array(
'type' => 'email',
'first_name' => 'email',
'second_name' => 'email-repeat',
//TRANSLATION GIVES ERROR ON NEXT LINE
'invalid_message' => $this->trans->trans('online.form.email.errors.equal', array(), 'messages_roadrunner'),
'error_bubbling' => true,
'first_options' => array('label' => $this->trans->trans("online.form.email.fields.one", array(), 'messages_roadrunner')),
'second_options' => array('label' => $this->trans->trans("online.form.email.fields.second", array(), 'messages_roadrunner')),
)
);
$builder->add('optin', 'checkbox', array(
'required' => false,
'label' => $this->trans->trans('online.form.email.fields.optin', array(), 'messages_roadrunner')
));
}
奇怪的是,在我的控制器中我使用相同的东西,但一切正常:
$content['text'] = $this->get('translator')->trans('online.tariff.text.no_advice', array(), 'messages_roadrunner');
有没有人有这个问题的经验?
提前致谢!