Permalink
Browse files

[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...
1 parent 56d61eb commit cc0df0a5aff1f5362373db951fd9d8b5fddc7de8 @webmozart webmozart committed Dec 3, 2012
Showing with 373 additions and 340 deletions.
  1. +21 −0 UPGRADE-2.2.md
  2. +2 −0 src/Symfony/Component/Validator/CHANGELOG.md
  3. +2 −2 src/Symfony/Component/Validator/Constraints/Choice.php
  4. +3 −3 src/Symfony/Component/Validator/Constraints/Count.php
  5. +3 −3 src/Symfony/Component/Validator/Constraints/Length.php
  6. +1 −1 src/Symfony/Component/Validator/Constraints/MaxLength.php
  7. +1 −1 src/Symfony/Component/Validator/Constraints/MinLength.php
  8. +11 −1 src/Symfony/Component/Validator/DefaultTranslator.php
  9. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.af.xlf
  10. +9 −9 src/Symfony/Component/Validator/Resources/translations/validators.bg.xlf
  11. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.ca.xlf
  12. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.cs.xlf
  13. +21 −21 src/Symfony/Component/Validator/Resources/translations/validators.cy.xlf
  14. +5 −5 src/Symfony/Component/Validator/Resources/translations/validators.da.xlf
  15. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.de.xlf
  16. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.en.xlf
  17. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.es.xlf
  18. +4 −4 src/Symfony/Component/Validator/Resources/translations/validators.et.xlf
  19. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.eu.xlf
  20. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.fa.xlf
  21. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.fi.xlf
  22. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.fr.xlf
  23. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.gl.xlf
  24. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.he.xlf
  25. +5 −5 src/Symfony/Component/Validator/Resources/translations/validators.hr.xlf
  26. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.hu.xlf
  27. +6 −6 src/Symfony/Component/Validator/Resources/translations/validators.hy.xlf
  28. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.id.xlf
  29. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.it.xlf
  30. +4 −4 src/Symfony/Component/Validator/Resources/translations/validators.ja.xlf
  31. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.lb.xlf
  32. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.lt.xlf
  33. +4 −4 src/Symfony/Component/Validator/Resources/translations/validators.mn.xlf
  34. +4 −4 src/Symfony/Component/Validator/Resources/translations/validators.nb.xlf
  35. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.nl.xlf
  36. +9 −9 src/Symfony/Component/Validator/Resources/translations/validators.no.xlf
  37. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.pl.xlf
  38. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.pt.xlf
  39. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.pt_BR.xlf
  40. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.ro.xlf
  41. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.ru.xlf
  42. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.sk.xlf
  43. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.sl.xlf
  44. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.sq.xlf
  45. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.sr_Cyrl.xlf
  46. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.sr_Latn.xlf
  47. +9 −9 src/Symfony/Component/Validator/Resources/translations/validators.sv.xlf
  48. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.tr.xlf
  49. +9 −9 src/Symfony/Component/Validator/Resources/translations/validators.uk.xlf
  50. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.zh_CN.xlf
View
@@ -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
@@ -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
-----
@@ -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}
@@ -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;
@@ -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';
@@ -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';
@@ -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';
@@ -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);
}
/**
@@ -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">
@@ -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">
@@ -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">
@@ -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">
@@ -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">
@@ -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">
@@ -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">
@@ -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>
@@ -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">
@@ -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">
@@ -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">
@@ -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">
Oops, something went wrong.

0 comments on commit cc0df0a

Please sign in to comment.