In Symfony2, you can translate your validation error messages:
Validation File
# src/Acme/BlogBundle/Resources/config/validation.yml
Acme\BlogBundle\Entity\Author:
properties:
name:
- NotBlank: { message: "author.name.not_blank" }
Translation File
# validators.en.yml
author.name.not_blank: Please enter an author name.
But how can I pass a parameter to the translation file, if e.g. I want to pass the required min or max length?
author.name.min_length: "Required length: %limit% characters."
What about,
Acme\BlogBundle\Entity\Author:
properties:
name:
- NotBlank: { message: "author.name.not_blank" }
- Length:
min: 3
minMessage: "author.name.min_length"
While your translation file should contain,
# validators.en.yml
author.name.not_blank: Please enter an author name.
author.name.min_length: "Required length: {{ limit }} characters."
The {{ limit }}
placeholder here will then fit the min
pamarater of the length constraint.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With