0

It's easy to translate security errors:

{{ error.messageKey|trans(error.messageData, 'security', 'fr') }}

But how translate in similar way (if it's possible in twig template) form validation errors which I can print in that way:

{{ form_errors(form.oneOfFormField) }}

I can't find information about how translate form validation errors (from asserts in form entity) by using already existing translation file in directory: SymfonyProjectName\vendor\symfony\symfony\src\Symfony\Component\Validator\Resources\translations\validators.fr.xlf. For example, when in form entity I have:

/**
* @Assert\LessThan(100)
*/
public $oneOfFormField;

In form, I can get the following error message: "This value should be less than 100.". How translate it by using said file. I'm using Symfony 3.1, but Symfony2 solutions usually works also.

Konrad
  • 77
  • 1
  • 9

1 Answers1

0

I found a solution here:

$this->get('translator')->setLocale('pl');

Read More: https://symfony.com/doc/current/components/translation/usage.html

Gopal Joshi
  • 2,350
  • 22
  • 49
Konrad
  • 77
  • 1
  • 9