4
4
How to Translate Validation Constraint Messages
5
5
===============================================
6
6
7
- If you're using validation constraints with the Form component, you can translate
8
- the error messages by creating a translation resource for the
9
- `` validators `` :ref: `domain <translation-resource-locations >`.
7
+ The validation constraints used in forms can translate their error messages by
8
+ creating a translation resource for the `` validators ``
9
+ :ref: `translation domain <translation-resource-locations >`.
10
10
11
- To start, suppose you've created a plain-old-PHP object that you need to
12
- use somewhere in your application::
11
+ First of all, install the Symfony translation component (if it's not already
12
+ installed in your application) running the following command:
13
+
14
+ .. code-block :: terminal
15
+
16
+ $ composer require symfony/translation
17
+
18
+ Suppose you've created a plain-old-PHP object that you need to use somewhere in
19
+ your application::
13
20
14
21
// src/Entity/Author.php
15
22
namespace App\Entity;
@@ -106,7 +113,7 @@ Now, create a ``validators`` catalog file in the ``translations/`` directory:
106
113
107
114
.. code-block :: xml
108
115
109
- <!-- translations/validators.en.xlf -->
116
+ <!-- translations/validators/validators .en.xlf -->
110
117
<?xml version =" 1.0" ?>
111
118
<xliff version =" 1.2" xmlns =" urn:oasis:names:tc:xliff:document:1.2" >
112
119
<file source-language =" en" datatype =" plaintext" original =" file.ext" >
@@ -121,12 +128,12 @@ Now, create a ``validators`` catalog file in the ``translations/`` directory:
121
128
122
129
.. code-block :: yaml
123
130
124
- # translations/validators.en.yaml
131
+ # translations/validators/validators .en.yaml
125
132
author.name.not_blank : Please enter an author name.
126
133
127
134
.. code-block :: php
128
135
129
- // translations/validators.en.php
136
+ // translations/validators/validators .en.php
130
137
return [
131
138
'author.name.not_blank' => 'Please enter an author name.',
132
139
];
0 commit comments