Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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().
  • Loading branch information
webmozart committed Jan 8, 2013
1 parent 56d61eb commit cc0df0a
Show file tree
Hide file tree
Showing 50 changed files with 373 additions and 340 deletions.
21 changes: 21 additions & 0 deletions UPGRADE-2.2.md
Expand Up @@ -206,6 +206,27 @@
}
```

* The sources of the pluralized messages in translation files have changed
from the singular to the pluralized version. If you created custom
translation files for validator errors, you should adapt them.

Before:

<trans-unit id="6">
<source>You must select at least {{ limit }} choices.</source>
<target>Sie müssen mindestens {{ limit }} Möglichkeit wählen.|Sie müssen mindestens {{ limit }} Möglichkeiten wählen.</target>
</trans-unit>

After:

<trans-unit id="6">
<source>You must select at least {{ limit }} choice.|You must select at least {{ limit }} choices.</source>
<target>Sie müssen mindestens {{ limit }} Möglichkeit wählen.|Sie müssen mindestens {{ limit }} Möglichkeiten wählen.</target>
</trans-unit>

Check the file src/Symfony/Component/Validator/Resources/translations/validators.en.xlf
for the new message sources.

#### Deprecations

* The interface `ClassMetadataFactoryInterface` was deprecated and will be
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Validator/CHANGELOG.md
Expand Up @@ -36,6 +36,8 @@ CHANGELOG
* [BC BREAK] inserted arguments `$translator` and `$translationDomain` in the constructor of `ValidationVisitor`
* [BC BREAK] inserted arguments `$translator` and `$translationDomain` in the constructor of `Validator`
* [BC BREAK] added `setTranslator()` and `setTranslationDomain()` to `ValidatorBuilderInterface`
* improved the Validator to support pluralized messages by default
* [BC BREAK] changed the source of all pluralized messages in the translation files to the pluralized version

2.1.0
-----
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Validator/Constraints/Choice.php
Expand Up @@ -28,8 +28,8 @@ class Choice extends Constraint
public $max = null;
public $message = 'The value you selected is not a valid choice.';
public $multipleMessage = 'One or more of the given values is invalid.';
public $minMessage = 'You must select at least {{ limit }} choices.';
public $maxMessage = 'You must select at most {{ limit }} choices.';
public $minMessage = 'You must select at least {{ limit }} choice.|You must select at least {{ limit }} choices.';
public $maxMessage = 'You must select at most {{ limit }} choice.|You must select at most {{ limit }} choices.';

/**
* {@inheritDoc}
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Validator/Constraints/Count.php
Expand Up @@ -21,9 +21,9 @@
*/
class Count extends Constraint
{
public $minMessage = 'This collection should contain {{ limit }} elements or more.';
public $maxMessage = 'This collection should contain {{ limit }} elements or less.';
public $exactMessage = 'This collection should contain exactly {{ limit }} elements.';
public $minMessage = 'This collection should contain {{ limit }} element or more.|This collection should contain {{ limit }} elements or more.';
public $maxMessage = 'This collection should contain {{ limit }} element or less.|This collection should contain {{ limit }} elements or less.';
public $exactMessage = 'This collection should contain exactly {{ limit }} element.|This collection should contain exactly {{ limit }} elements.';
public $min;
public $max;

Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Validator/Constraints/Length.php
Expand Up @@ -21,9 +21,9 @@
*/
class Length extends Constraint
{
public $maxMessage = 'This value is too long. It should have {{ limit }} characters or less.';
public $minMessage = 'This value is too short. It should have {{ limit }} characters or more.';
public $exactMessage = 'This value should have exactly {{ limit }} characters.';
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.';
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.';
public $exactMessage = 'This value should have exactly {{ limit }} character.|This value should have exactly {{ limit }} characters.';
public $max;
public $min;
public $charset = 'UTF-8';
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraints/MaxLength.php
Expand Up @@ -22,7 +22,7 @@
*/
class MaxLength extends Constraint
{
public $message = 'This value is too long. It should have {{ limit }} characters or less.';
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.';
public $limit;
public $charset = 'UTF-8';

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraints/MinLength.php
Expand Up @@ -22,7 +22,7 @@
*/
class MinLength extends Constraint
{
public $message = 'This value is too short. It should have {{ limit }} characters or more.';
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.';
public $limit;
public $charset = 'UTF-8';

Expand Down
12 changes: 11 additions & 1 deletion src/Symfony/Component/Validator/DefaultTranslator.php
Expand Up @@ -36,7 +36,17 @@ public function trans($id, array $parameters = array(), $domain = null, $locale
*/
public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null)
{
return strtr($id, $parameters);
$ids = explode('|', $id);

if (1 == $number) {
return strtr($ids[0], $parameters);
}

if (!isset($ids[1])) {
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));
}

return strtr($ids[1], $parameters);
}

/**
Expand Down
Expand Up @@ -23,11 +23,11 @@
<target>Die waarde wat jy gekies het is nie 'n geldige keuse nie.</target>
</trans-unit>
<trans-unit id="6">
<source>You must select at least {{ limit }} choices.</source>
<source>You must select at least {{ limit }} choice.|You must select at least {{ limit }} choices.</source>
<target>Jy moet ten minste {{ limit }} kies.|Jy moet ten minste {{ limit }} keuses kies.</target>
</trans-unit>
<trans-unit id="7">
<source>You must select at most {{ limit }} choices.</source>
<source>You must select at most {{ limit }} choice.|You must select at most {{ limit }} choices.</source>
<target>Jy moet by die meeste {{ limit }} keuse kies.|Jy moet by die meeste {{ limit }} keuses kies.</target>
</trans-unit>
<trans-unit id="8">
Expand Down Expand Up @@ -75,15 +75,15 @@
<target>Hierdie waarde moet {{ limit }} of minder wees.</target>
</trans-unit>
<trans-unit id="19">
<source>This value is too long. It should have {{ limit }} characters or less.</source>
<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>
<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>
</trans-unit>
<trans-unit id="20">
<source>This value should be {{ limit }} or more.</source>
<target>Hierdie waarde moet {{ limit }} of meer wees.</target>
</trans-unit>
<trans-unit id="21">
<source>This value is too short. It should have {{ limit }} characters or more.</source>
<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>
<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>
</trans-unit>
<trans-unit id="22">
Expand Down Expand Up @@ -179,7 +179,7 @@
<target>Hierdie waarde moet die huidige wagwoord van die gebruiker wees.</target>
</trans-unit>
<trans-unit id="48">
<source>This value should have exactly {{ limit }} characters.</source>
<source>This value should have exactly {{ limit }} character.|This value should have exactly {{ limit }} characters.</source>
<target>Hierdie waarde moet presies {{ limit }} karakter wees.|Hierdie waarde moet presies {{ limit }} karakters wees.</target>
</trans-unit>
<trans-unit id="49">
Expand All @@ -203,15 +203,15 @@
<target>'n PHP-uitbreiding veroorsaak die oplaai van die lêer om te misluk.</target>
</trans-unit>
<trans-unit id="54">
<source>This collection should contain {{ limit }} elements or more.</source>
<source>This collection should contain {{ limit }} element or more.|This collection should contain {{ limit }} elements or more.</source>
<target>Hierdie versameling moet {{ limit }} element of meer bevat.|Hierdie versameling moet {{ limit }} elemente of meer bevat.</target>
</trans-unit>
<trans-unit id="55">
<source>This collection should contain {{ limit }} elements or less.</source>
<source>This collection should contain {{ limit }} element or less.|This collection should contain {{ limit }} elements or less.</source>
<target>Hierdie versameling moet {{ limit }} element of minder bevat.|Hierdie versameling moet {{ limit }} elemente of meer bevat.</target>
</trans-unit>
<trans-unit id="56">
<source>This collection should contain exactly {{ limit }} elements.</source>
<source>This collection should contain exactly {{ limit }} element.|This collection should contain exactly {{ limit }} elements.</source>
<target>Hierdie versameling moet presies {{ limit }} element bevat.|Hierdie versameling moet presies {{ limit }} elemente bevat.</target>
</trans-unit>
<trans-unit id="57">
Expand Down
Expand Up @@ -23,11 +23,11 @@
<target>Избраната стойност е невалидна.</target>
</trans-unit>
<trans-unit id="6">
<source>You must select at least {{ limit }} choices.</source>
<source>You must select at least {{ limit }} choice.|You must select at least {{ limit }} choices.</source>
<target>Трябва да изберете поне {{ limit }} опция.|Трябва да изберете поне {{ limit }} опции.</target>
</trans-unit>
<trans-unit id="7">
<source>You must select at most {{ limit }} choices.</source>
<source>You must select at most {{ limit }} choice.|You must select at most {{ limit }} choices.</source>
<target>Трябва да изберете най-много {{ limit }} опция.|Трябва да изберете най-много {{ limit }} опции.</target>
</trans-unit>
<trans-unit id="8">
Expand Down Expand Up @@ -75,15 +75,15 @@
<target>Стойността трябва да бъде {{ limit }} или по-малко.</target>
</trans-unit>
<trans-unit id="19">
<source>This value is too long. It should have {{ limit }} characters or less.</source>
<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>
<target>Стойността е твърде дълга. Трябва да съдържа най-много {{ limit }} символ.|Стойността е твърде дълга. Трябва да съдържа най-много {{ limit }} символа.</target>
</trans-unit>
<trans-unit id="20">
<source>This value should be {{ limit }} or more.</source>
<target>Стойността трябва да бъде {{ limit }} или повече.</target>
</trans-unit>
<trans-unit id="21">
<source>This value is too short. It should have {{ limit }} characters or more.</source>
<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>
<target>Стойността е твърде кратка. Трябва да съдържа поне {{ limit }} символ.|Стойността е твърде кратка. Трябва да съдържа поне {{ limit }} символа.</target>
</trans-unit>
<trans-unit id="22">
Expand Down Expand Up @@ -179,7 +179,7 @@
<target>Стойността трябва да бъде текущата потребителска парола.</target>
</trans-unit>
<trans-unit id="48">
<source>This value should have exactly {{ limit }} characters.</source>
<source>This value should have exactly {{ limit }} character.|This value should have exactly {{ limit }} characters.</source>
<target>Стойността трябва да бъде точно {{ limit }} символ.|Стойността трябва да бъде точно {{ limit }} символа.</target>
</trans-unit>
<trans-unit id="49">
Expand All @@ -203,17 +203,17 @@
<target>PHP разширение предизвика прекъсване на качването.</target>
</trans-unit>
<trans-unit id="54">
<source>This collection should contain {{ limit }} elements or more.</source>
<source>This collection should contain {{ limit }} element or more.|This collection should contain {{ limit }} elements or more.</source>
<target>Колекцията трябва да съдържа поне {{ limit }} елемент.|Колекцията трябва да съдържа поне {{ limit }} елемента.</target>
</trans-unit>
<trans-unit id="55">
<source>This collection should contain {{ limit }} elements or less.</source>
<source>This collection should contain {{ limit }} element or less.|This collection should contain {{ limit }} elements or less.</source>
<target>Колекцията трябва да съдържа най-много {{ limit }} елемент.|Колекцията трябва да съдържа най-много {{ limit }} елемента.</target>
</trans-unit>
<trans-unit id="56">
<source>This collection should contain exactly {{ limit }} elements.</source>
<source>This collection should contain exactly {{ limit }} element.|This collection should contain exactly {{ limit }} elements.</source>
<target>Колекцията трябва да съдържа точно {{ limit }} елемент.|Колекцията трябва да съдържа точно {{ limit }} елемента.</target>
</trans-unit>
</body>
</file>
</xliff>
</xliff>
Expand Up @@ -23,11 +23,11 @@
<target>El valor seleccionat no és una opció vàlida.</target>
</trans-unit>
<trans-unit id="6">
<source>You must select at least {{ limit }} choices.</source>
<source>You must select at least {{ limit }} choice.|You must select at least {{ limit }} choices.</source>
<target>Ha de seleccionar almenys {{ limit }} opció.|Ha de seleccionar almenys {{ limit }} opcions.</target>
</trans-unit>
<trans-unit id="7">
<source>You must select at most {{ limit }} choices.</source>
<source>You must select at most {{ limit }} choice.|You must select at most {{ limit }} choices.</source>
<target>Ha de seleccionar com a màxim {{ limit }} opció.|Ha de seleccionar com a màxim {{ limit }} opcions.</target>
</trans-unit>
<trans-unit id="8">
Expand Down Expand Up @@ -75,15 +75,15 @@
<target>Aquest valor hauria de ser {{ limit }} o menys.</target>
</trans-unit>
<trans-unit id="19">
<source>This value is too long. It should have {{ limit }} characters or less.</source>
<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>
<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>
</trans-unit>
<trans-unit id="20">
<source>This value should be {{ limit }} or more.</source>
<target>Aquest valor hauria de ser {{ limit }} o més.</target>
</trans-unit>
<trans-unit id="21">
<source>This value is too short. It should have {{ limit }} characters or more.</source>
<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>
<target>Aquest valor és massa curt. Hauria de tenir {{ limit }} caràcters o més.</target>
</trans-unit>
<trans-unit id="22">
Expand Down Expand Up @@ -179,7 +179,7 @@
<target>Aquest valor hauria de ser la contrasenya actual de l'usuari.</target>
</trans-unit>
<trans-unit id="48">
<source>This value should have exactly {{ limit }} characters.</source>
<source>This value should have exactly {{ limit }} character.|This value should have exactly {{ limit }} characters.</source>
<target>Aquest valor hauria de tenir exactament {{ limit }} caràcter.|Aquest valor hauria de tenir exactament {{ limit }} caràcters.</target>
</trans-unit>
<trans-unit id="49">
Expand All @@ -203,15 +203,15 @@
<target>Una extensió de PHP va fer que la pujada fallara.</target>
</trans-unit>
<trans-unit id="54">
<source>This collection should contain {{ limit }} elements or more.</source>
<source>This collection should contain {{ limit }} element or more.|This collection should contain {{ limit }} elements or more.</source>
<target>Aquesta col·lecció ha de contenir {{ limit }} element o més.|Aquesta col·lecció ha de contenir {{ limit }} elements o més.</target>
</trans-unit>
<trans-unit id="55">
<source>This collection should contain {{ limit }} elements or less.</source>
<source>This collection should contain {{ limit }} element or less.|This collection should contain {{ limit }} elements or less.</source>
<target>Aquesta col·lecció ha de contenir {{ limit }} element o menys.|Aquesta col·lecció ha de contenir {{ limit }} elements o menys.</target>
</trans-unit>
<trans-unit id="56">
<source>This collection should contain exactly {{ limit }} elements.</source>
<source>This collection should contain exactly {{ limit }} element.|This collection should contain exactly {{ limit }} elements.</source>
<target>Aquesta col·lecció ha de contenir exactament {{ limit }} element.|Aquesta col·lecció ha de contenir exactament {{ limit }} elements.</target>
</trans-unit>
<trans-unit id="57">
Expand Down

0 comments on commit cc0df0a

Please sign in to comment.