Symfony2 translation of verification messages

I have a general problem with translating validator messages to Symfony, and all the solutions I offer do not help me. This is my limitation:

//  src/AppBundle/Entity/Friend.php   
/**
         * @var string
         *
         * @Assert\NotBlank(message = "test")
         *
         * @ORM\Column(name="name", type="string", length=255)
         */
        private $name;

And the file with translations:

// src/AppBundle/Resources/translations/validators.en.yml
test: my message

The same file with translations, which I also added in the application directory. In fact, this does not work. What am I missing?

+4
source share
1 answer

If you follow these steps, it should work:

First turn on the translation system:

# app/config/config.yml
framework:
    translator: { fallback: en }

Create a constraint, just like you:

// src/AppBundle/Entity/Friend.php
use Symfony\Component\Validator\Constraints as Assert;// Don't forget this part.

class Friend
{
    /**
     * @var string
     * @Assert\NotBlank(message = "test")
     * @ORM\Column(name="name", type="string", length=255)
     */
    public $name;
}

Create a translation file in the validator directory for constraint messages, usually in the Resources / translations / directory of the directory, just like you.

# validators.en.yml
test: my message

. , , ( , dev).

$ php app/console cache:clear

.

+13

Source: https://habr.com/ru/post/1570752/


All Articles