表单 – Symfony2:如何在表单类型中翻译自定义错误消息?

前端之家收集整理的这篇文章主要介绍了表单 – Symfony2:如何在表单类型中翻译自定义错误消息?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要翻译我的表单类型的错误消息.这是我的表单类型代码
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',array(
        'label' => 'Email 2 :','required' => false,));
    $builder->add('email3',array(
        'label' => 'Email 3 :',));
    $builder->add('email4',array(
        'label' => 'Email 4 :',));
    $builder->add('email5',array(
        'label' => 'Email 5 :',));
    $builder->add('subject','text',array(
        'data' => $defaultSubject,'required' => true,'label' => 'Subject* :',));
    $builder->add('message','textarea',array(
        'data' => $defaultMessage,'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';
}

}

我想翻译“你必须在getDefaultOptions()方法中输入至少一个电子邮件地址进行有效的提交”为法语.我已经在messages.fr.yml中添加了翻译.但它没有得到翻译.有什么想法可以怎么做?

解决方法

验证转换到validators.LANG.yml文件 – 不是messages.LANG.yml文件.
原文链接:https://www.f2er.com/html/231114.html

猜你在找的HTML相关文章