Symfony2: How to translate custom error messages in form types?

后端 未结 4 806
梦谈多话
梦谈多话 2021-02-12 15:41

I need to translate the error messages from my form type. Here is my form Type code:

class ReferFriendType extends AbstractType {

public function buildForm(Form         


        
相关标签:
4条回答
  • 2021-02-12 15:56

    It`s easy, see http://symfony.com/doc/current/book/translation.html#translating-constraint-messages And set default_locale in /app/config/config.yml or play with $this->get('request')->setLocale('ru');

    0 讨论(0)
  • 2021-02-12 16:01

    Validation translations go to the validators.LANG.yml files — not messages.LANG.yml ones.

    0 讨论(0)
  • 2021-02-12 16:03

    There is an example in the docs.

    0 讨论(0)
  • 2021-02-12 16:16

    The replacements are not set in the validation.yml file but by the Validator.

    validators.en.yml

    noFirstnameMinLimit: Please provide at least {{ limit }} characters
    

    validation.yml

    Acm\AddressBundle\Entity\Address:
        properties:
            firstname:
                - Length:
                    min: 3 
                    minMessage: "noFirstnameMinLimit"
    

    This works for me with Symfony 2.4

    0 讨论(0)
提交回复
热议问题