10000 [Validator] Changed validator to support pluralized messages by default · symfony/symfony@cc0df0a · GitHub
[go: up one dir, main page]

Skip to content

Commit cc0df0a

Browse files
committed
[Validator] Changed validator to support pluralized messages by default
This was implemented in order to satisfy Drupal's requirements for a singular and a plural message whenever a message is passed to their implementation of transChoice().
1 parent 56d61eb commit cc0df0a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+373
-340
lines changed

UPGRADE-2.2.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,27 @@
206206
}
207207
```
208208

209+
* The sources of the pluralized messages in translation files have changed
210+
from the singular to the pluralized version. If you created custom
211+
translation files for validator errors, you should adapt them.
212+
213+
Before:
214+
215+
<trans-unit id="6">
216+
<source>You must select at least {{ limit }} choices.</source>
217+
<target>Sie müssen mindestens {{ limit }} Möglichkeit wählen.|Sie müssen mindestens {{ limit }} Möglichkeiten wählen.</target>
218+
</trans-unit>
219+
220+
After:
221+
222+
<trans-unit id="6">
223+
<source>You must select at least {{ limit }} choice.|You must select at least {{ limit }} choices.</source>
224+
<target>Sie müssen mindestens {{ limit }} Möglichkeit wählen.|Sie müssen mindestens {{ limit }} Möglichkeiten wählen.</target>
225+
</trans-unit>
226+
227+
Check the file src/Symfony/Component/Validator/Resources/translations/validators.en.xlf
228+
for the new message sources.
229+
209230
#### Deprecations
210231

211232
* The interface `ClassMetadataFactoryInterface` was deprecated and will be

src/Symfony/Component/Validator/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ CHANGELOG
3636
* [BC BREAK] inserted arguments `$translator` and `$translationDomain` in the constructor of `ValidationVisitor`
3737
* [BC BREAK] inserted arguments `$translator` and `$translationDomain` in the constructor of `Validator`
3838
* [BC BREAK] added `setTranslator()` and `setTranslationDomain()` to `ValidatorBuilderInterface`
39+
* improved the Validator to support pluralized messages by default
40+
* [BC BREAK] changed the source of all pluralized messages in the translation files to the pluralized version
3941

4042
2.1.0
4143
-----

src/Symfony/Component/Validator/Constraints/Choice.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class Choice extends Constraint
2828
public $max = null;
2929
public $message = 'The value you selected is not a valid choice.';
3030
public $multipleMessage = 'One or more of the given values is invalid.';
31-
public $minMessage = 'You must select at least {{ limit }} choices.';
32-
public $maxMessage = 'You must select at most {{ limit }} choices.';
31+
public $minMessage = 'You must select at least {{ limit }} choice.|You must select at least {{ limit }} choices.';
32+
public $maxMessage = 'You must select at most {{ limit }} choice.|You must select at most {{ limit }} choices.';
3333

3434
/**
3535
* {@inheritDoc}

src/Symfony/Component/Validator/Constraints/Count.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
*/
2222
class Count extends Constraint
2323
{
24-
public $minMessage = 'This collection should contain {{ limit }} elements or more.';
25-
public $maxMessage = 'This collection should contain {{ limit }} elements or less.';
26-
public $exactMessage = 'This collection should contain exactly {{ limit }} elements.';
24+
public $minMessage = 'This collection should contain {{ limit }} element or more.|This collection should contain {{ limit }} elements or more.';
25+
public $maxMessage = 'This collection should contain {{ limit }} element or less.|This collection should contain {{ limit }} elements or less.';
26+
public $exactMessage = 'This collection should contain exactly {{ limit }} element.|This collection should contain exactly {{ limit }} elements.';
2727
public $min;
2828
public $max;
2929

src/Symfony/Component/Validator/Constraints/Length.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
*/
2222
class Length extends Constraint
2323
{
24-
public $maxMessage = 'This value is too long. It should have {{ limit }} characters or less.';
25-
public $minMessage = 'This value is too short. It should have {{ limit }} characters or more.';
26-
public $exactMessage = 'This value should have exactly {{ limit }} characters.';
24+
public $maxMessage = 'This value is too long. It should have {{ limit }} character or less.|This value is too long. It should have {{ limit }} characters or less.';
25+
public $minMessage = 'This value is too short. It should have {{ limit }} character or more.|This value is too short. It should have {{ limit }} characters or more.';
26+
public $exactMessage = 'This value should have exactly {{ limit }} character.|This value should have exactly {{ limit }} characters.';
2727
public $max;
2828
public $min;
2929
public $charset = 'UTF-8';

src/Symfony/Component/Validator/Constraints/MaxLength.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
class MaxLength extends Constraint
2424
{
25-
public $message = 'This value is too long. It should have {{ limit }} characters or less.';
25+
public $message = 'This value is too long. It should have {{ limit }} character or less.|This value is too long. It should have {{ limit }} characters or less.';
2626
public $limit;
2727
public $charset = 'UTF-8';
2828

src/Symfony/Component/Validator/Constraints/MinLength.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
class MinLength extends Constraint
2424
{
25-
public $message = 'This value is too short. It should have {{ limit }} characters or more.';
25+
public $message = 'This value is too short. It should have {{ limit }} character or more.|This value is too short. It should have {{ limit }} characters or more.';
2626
public $limit;
2727
public $charset = 'UTF-8';
2828

src/Symfony/Component/Validator/DefaultTranslator.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,17 @@ public function trans($id, array $parameters = array(), $domain = null, $locale
3636
*/
3737
public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null)
3838
{
39-
return strtr($id, $parameters);
39+
$ids = explode('|', $id);
40+
41+
if (1 == $number) {
42+
return strtr($ids[0], $parameters);
43+
}
44+
45+
if (!isset($ids[1])) {
46+
throw new \InvalidArgumentException(sprintf('The message "%s" cannot be pluralized, because it is missing a plural (e.g. "There is one apple|There are %%count%% apples").', $id));
47+
}
48+
49+
return strtr($ids[1], $parameters);
4050
}
4151

4252
/**

src/Symfony/Component/Validator/Resources/translations/validators.af.xlf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
<target>Die waarde wat jy gekies het is nie 'n geldige keuse nie.</target>
2424
</trans-unit>
2525
<trans-unit id="6">
26-
<source>You must select at least {{ limit }} choices.</source>
26+
<source>You must select at least {{ limit }} choice.|You must select at least {{ limit }} choices.</source>
2727
<target>Jy moet ten minste {{ limit }} kies.|Jy moet ten minste {{ limit }} keuses kies.</target>
2828
</trans-unit>
2929
<trans-unit id="7">
30-
<source>You must select at most {{ limit }} choices.</source>
30+
<source>You must select at most {{ limit }} choice.|You must select at most {{ limit }} choices.</source>
3131
<target>Jy moet by die meeste {{ limit }} keuse kies.|Jy moet by die meeste {{ limit }} keuses kies.</target>
3232
</trans-unit>
3333
<trans-unit id="8">
@@ -75,15 +75,15 @@
7575
<target>Hierdie waarde moet {{ limit }} of minder wees.</target>
7676
</trans-unit>
7777
<trans-unit id="19">
78-
<source>This value is too long. It should have {{ limit }} characters or less.</source>
78+
<source>This value is too long. It should have {{ limit }} character or less.|This value is too long. It should have {{ limit }} characters or less.</source>
7979
<target>Hierdie waarde is te lank. Dit moet {{ limit }} karakter of minder wees.|Hierdie waarde is te lank. Dit moet {{ limit }} karakters of minder wees.</target>
8080
</trans-unit>
8181
<trans-unit id="20">
8282
<source>This value should be {{ limit }} or more.</source>
8383
<target>Hierdie waarde moet {{ limit }} of meer wees.</target>
8484
</trans-unit>
8585
<trans-unit id="21">
86-
<source>This value is too short. It should have {{ limit }} characters or more.</source>
86+
<source>This value is too short. It should have {{ limit }} character or more.|This value is too short. It should have {{ limit }} characters or more.</source>
8787
<target>Hierdie waarde is te kort. Dit moet {{ limit }} karakter of meer wees.|Hierdie waarde is te kort. Dit moet {{ limit }} karakters of meer wees.</target>
8888
</trans-unit>
8989
<trans-unit id="22">
@@ -179,7 +179,7 @@
179179
<target>Hierdie waarde moet die huidige wagwoord van die gebruiker wees.</target>
180180
</trans-unit>
181181
<trans-unit id="48">
182-
<source>This value should have exactly {{ limit }} characters.</source>
182+
<source>This value should have exactly {{ limit }} character.|This value should have exactly {{ limit }} characters.</source>
183183
<target>Hierdie waarde moet presies {{ limit }} karakter wees.|Hierdie waarde moet presies {{ limit }} karakters wees.</target>
184184
</trans-unit>
185185
<trans-unit id="49">
@@ -203,15 +203,15 @@
203203
<target>'n PHP-uitbreiding veroorsaak die oplaai van die lêer om te misluk.</target>
204204
</trans-unit>
205205
<trans-unit id="54">
206-
<source>This collection should contain {{ limit }} elements or more.</source>
206+
<source>This collection should contain {{ limit }} element or more.|This collection should contain {{ limit }} elements or more.</source>
207207
<target>Hierdie versameling moet {{ limit }} element of meer bevat.|Hierdie versameling moet {{ limit }} elemente of meer bevat.</target>
208208
</trans-unit>
209209
<trans-unit id="55">
210-
<source>This collection should contain {{ limit }} elements or less.</source>
210+
<source>This collection should contain {{ limit }} element or less.|This collection should contain {{ limit }} elements or less.</source>
211211
<target>Hierdie versameling moet {{ limit }} element of minder bevat.|Hierdie versameling moet {{ limit }} elemente of meer bevat.</target>
212212
</trans-unit>
213213
<trans-unit id="56">
214-
<source>This collection should contain exactly {{ limit }} elements.</source>
214+
<source>This collection should contain exactly {{ limit }} element.|This collection should contain exactly {{ limit }} elements.</source>
215215
<target>Hierdie versameling moet presies {{ limit }} element bevat.|Hierdie versameling moet presies {{ limit }} elemente bevat.</target>
216216
</trans-unit>
217217
<trans-unit id="57">

src/Symfony/Component/Validator/Resources/translations/validators.bg.xlf

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
<target>Избраната стойност е невалидна.</target>
2424
</trans-unit>
2525
<trans-unit id="6">
26-
<source>You must select at least {{ limit }} choices.</source>
26+
<source>You must select at least {{ limit }} choice.|You must select at least {{ limit }} choices.</source>
2727
<target>Трябва да изберете поне {{ limit }} опция.|Трябва да изберете поне {{ limit }} опции.</target>
2828
</trans-unit>
2929
<trans-unit id="7">
30-
<source>You must select at most {{ limit }} choices.</source>
30+
<source>You must select at most {{ limit }} choice.|You must select at most {{ limit }} choices.</source>
3131
<target>Трябва да изберете най-много {{ limit }} опция.|Трябва да изберете най-много {{ limit }} опции.</target>
3232
</trans-unit>
3333
<trans-unit id="8">
@@ -75,15 +75,15 @@
7575
<target>Стойността трябва да бъде {{ limit }} или по-малко.</target>
7676
</trans-unit>
7777
<trans-unit id="19">
78-
<source>This value is too long. It should have {{ limit }} characters or less.</source>
78+
<source>This value is too long. It should have {{ limit }} character or less.|This value is too long. It should have {{ limit }} characters or less.</source>
7979
<target>Стойността е твърде дълга. Трябва да съдържа най-много {{ limit }} символ.|Стойността е твърде дълга. Трябва да съдържа най-много {{ limit }} символа.</target>
8080
</trans-unit>
8181
<trans-unit id="20">
8282
<source>This value should be {{ limit }} or more.</source>
8383
<target>Стойността трябва да бъде {{ limit }} или повече.</target>
8484
</trans-unit>
8585
<trans-unit id="21">
86-
<source>This value is too short. It should have {{ limit }} characters or more.</source>
86+
<source>This value is too short. It should have {{ limit }} character or more.|This value is too short. It should have {{ limit }} characters or more.</source>
8787
<target>Стойността е твърде кратка. Трябва да съдържа поне {{ limit }} символ.|Стойността е твърде кратка. Трябва да съдържа поне {{ limit }} символа.</target>
8888
</trans-unit>
8989
<trans-unit id="22">
@@ -179,7 +179,7 @@
179179
<target>Стойността трябва да бъде текущата потребителска парола.</target>
180180
</trans-unit>
181181
<trans-unit id="48">
182-
<source>This value should have exactly {{ limit }} characters.</source>
182+
<source>This value should have exactly {{ limit }} character.|This value should have exactly {{ limit }} characters.</source>
183183
<target>Стойността трябва да бъде точно {{ limit }} символ.|Стойността трябва да бъде точно {{ limit }} символа.</target>
184184
</trans-unit>
185185
<trans-unit id="49">
@@ -203,17 +203,17 @@
203203
<target>PHP разширение предизвика прекъсване на качването.</target>
204204
</trans-unit>
205205
<trans-unit id="54">
206-
<source>This collection should contain {{ limit }} elements or more.</source>
206+
<source>This collection should contain {{ limit }} element or more.|This collection should contain {{ limit }} elements or more.</source>
207207
<target>Колекцията трябва да съдържа поне {{ limit }} елемент.|Колекцията трябва да съдържа поне {{ limit }} елемента.</target>
208208
</trans-unit>
209209
<trans-unit id="55">
210-
<source>This collection should contain {{ limit }} elements or less.</source>
210+
<source>This collection should contain {{ limit }} element or less.|This collection should contain {{ limit }} elements or less.</source>
211211
<target>Колекцията трябва да съдържа най-много {{ limit }} елемент.|Колекцията трябва да съдържа най-много {{ limit }} елемента.</target>
212212
</trans-unit>
213213
<trans-unit id="56">
214-
<source>This collection should contain exactly {{ limit }} elements.</source>
214+
<source>This collection should contain exactly {{ limit }} element.|This collection should contain exactly {{ limit }} elements.</source>
215215
<target>Колекцията трябва да съдържа точно {{ limit }} елемент.|Колекцията трябва да съдържа точно {{ limit }} елемента.</target>
216216
</trans-unit>
217217
</body>
218218
</file>
219-
</xliff>
219+
</xliff>

src/Symfony/Component/Validator/Resources/translations/validators.ca.xlf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
<target>El valor seleccionat no és una opció vàlida.</target>
2424
</trans-unit>
2525
<trans-unit id="6">
26-
<source>You must select at least {{ limit }} choices.</source>
26+
<source>You must select at least {{ limit }} choice.|You must select at least {{ limit }} choices.</source>
2727
<target>Ha de seleccionar almenys {{ limit }} opció.|Ha de seleccionar almenys {{ limit }} opcions.</target>
2828
</trans-unit>
2929
<trans-unit id="7">
30-
<source>You must select at most {{ limit }} choices.</source>
30+
<source>You must select at most {{ limit }} choice.|You must select at most {{ limit }} choices.</source>
3131
<target>Ha de seleccionar com a màxim {{ limit }} opció.|Ha de seleccionar com a màxim {{ limit }} opcions.</target>
3232
</trans-unit>
3333
<trans-unit id="8">
@@ -75,15 +75,15 @@
7575
<target>Aquest valor hauria de ser {{ limit }} o menys.</target>
7676
</trans-unit>
7777
<trans-unit id="19">
78-
<source>This value is too long. It should have {{ limit }} characters or less.</source>
78+
<source>This value is too long. It should have {{ limit }} character or less.|This value is too long. It should have {{ limit }} characters or less.</source>
7979
<target>Aquest valor és massa llarg. Hauria de tenir {{ limit }} caràcter o menys.|Aquest valor és massa llarg. Hauria de tenir {{ limit }} caràcters o menys.</target>
8080
</trans-unit>
8181
<trans-unit id="20">
8282
<source>This value should be {{ limit }} or more.</source>
8383
<target>Aquest valor hauria de ser {{ limit }} o més.</target>
8484
</trans-unit>
8585
<trans-unit id="21">
86-
<source>This value is too short. It should have {{ limit }} characters or more.</source>
86+
<source>This value is too short. It should have {{ limit }} character or more.|This value is too short. It should have {{ limit }} characters or more.</source>
8787
<target>Aquest valor és massa curt. Hauria de tenir {{ limit }} caràcters o més.</target>
8888
</trans-unit>
8989
<trans-unit id="22">
@@ -179,7 +179,7 @@
179179
<target>Aquest valor hauria de ser la contrasenya actual de l'usuari.</target>
180180
</trans-unit>
181181
<trans-unit id="48">
182-
<source>This value should have exactly {{ limit }} characters.</source>
182+
<source>This value should have exactly {{ limit }} character.|This value should have exactly {{ limit }} characters.</source>
183183
<target>Aquest valor hauria de tenir exactament {{ limit }} caràcter.|Aquest valor hauria de tenir exactament {{ limit }} caràcters.</target>
184184
</trans-unit>
185185
<trans-unit id="49">
@@ -203,15 +203,15 @@
203203
<target>Una extensió de PHP va fer que la pujada fallara.</target>
204204
</trans-unit>
205205
<trans-unit id="54">
206-
<source>This collection should contain {{ limit }} elements or more.</source>
206+
<source>This collection should contain {{ limit }} element or more.|This collection should contain {{ limit }} elements or more.</source>
207207
<target>Aquesta col·lecció ha de contenir {{ limit }} element o més.|Aquesta col·lecció ha de contenir {{ limit }} elements o més.</target>
208208
</trans-unit>
209209
<trans-unit id="55">
210-
<source>This collection should contain {{ limit }} elements or less.</source>
210+
<source>This collection should contain {{ limit }} element or less.|This collection should contain {{ limit }} elements or less.</source>
211211
<target>Aquesta col·lecció ha de contenir {{ limit }} element o menys.|Aquesta col·lecció ha de contenir {{ limit }} elements o menys.</target>
212212
</trans-unit>
213213
<trans-unit id="56">
214-
<source>This collection should contain exactly {{ limit }} elements.</source>
214+
<source>This collection should contain exactly {{ limit }} element.|This collection should contain exactly {{ limit }} elements.</source>
215215
<target>Aquesta col·lecció ha de contenir exactament {{ limit }} element.|Aquesta col·lecció ha de contenir exactament {{ limit }} elements.</target>
216216
</trans-unit>
217217
<trans-unit id="57">

0 commit comments

Comments
 (0)
0