Vis*_*mar 19 forms internationalization symfony
我需要从表单类型中翻译错误消息.这是我的表单类型代码:
class ReferFriendType extends AbstractType {
public function buildForm(FormBuilder $builder, array $options)
{
$defaultSubject = "This is a default referral subject.";
$defaultMessage = "This is a default referral message.";
$builder->add('email1', 'email',array(
'required' => true,
'label' => 'Email 1* :',
'attr' => array('class' => 'large_text'),
));
$builder->add('email2', 'email',array(
'label' => 'Email 2 :',
'required' => false,
'attr' => array('class' => 'large_text'),
));
$builder->add('email3', 'email',array(
'label' => 'Email 3 :',
'required' => false,
'attr' => array('class' => 'large_text'),
));
$builder->add('email4', 'email',array(
'label' => 'Email 4 :',
'required' => false,
'attr' => array('class' => 'large_text'),
));
$builder->add('email5', 'email',array(
'label' => 'Email 5 :',
'required' => false,
'attr' => array('class' => 'large_text'),
));
$builder->add('subject', 'text', array(
'data' => $defaultSubject,
'required' => true,
'label' => 'Subject* :',
'attr' => array('class' => 'large_text'),
));
$builder->add('message', 'textarea', array(
'data' => $defaultMessage,
'required' => true,
'label' => 'Message* :',
'attr' => array('rows' => '5', 'cols' => '40'),
));
}
public function getDefaultOptions(array $options)
{
$collectionConstraint = new Collection( array(
'fields' => array(
'email1' => array(
new Email(),
new NotBlank(array(
'message' => 'You must enter atleast one email address for a valid submission',
)),
),
'subject' => new NotBlank(),
'message' => new NotBlank(),
),
'allowExtraFields' => true,
'allowMissingFields' => true,
));
return array(
'validation_constraint' => $collectionConstraint,
'csrf_protection' => false,
);
}
public function getName()
{
return 'referFriend';
}
Run Code Online (Sandbox Code Playgroud)
}
我想在getDefaultOptions()方法中将"您必须输入至少一个有效提交的电子邮件地址"翻译成法语.我在messages.fr.yml中添加了翻译.但它没有得到翻译.有什么想法可以做到这一点?
Eln*_*mov 38
验证翻译转到validators.LANG.yml文件 - 而不是文件messages.LANG.yml.
| 归档时间: |
|
| 查看次数: |
24017 次 |
| 最近记录: |