Zend_Validate-Messages.xml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- EN-Revision: 20352 -->
  3. <!-- Reviewed: no -->
  4. <sect1 id="zend.validate.messages">
  5. <title>Messages de validation</title>
  6. <para>
  7. Chaque validateur basé sur <classname>Zend_Validate</classname> propose un ou plusieurs messages
  8. dans le cas d'un echec. Vous pouvez utiliser ces informations pour créer vos propres messages
  9. ou pour traduire les messages présents.
  10. </para>
  11. <para>
  12. These validation messages are constants which can be found at top of each validator class.
  13. Let's look into <classname>Zend_Validate_GreaterThan</classname> for an descriptive example:
  14. </para>
  15. <programlisting language="php"><![CDATA[
  16. protected $_messageTemplates = array(
  17. self::NOT_GREATER => "'%value%' is not greater than '%min%'",
  18. );
  19. ]]></programlisting>
  20. <para>
  21. As you can see the constant <constant>self::NOT_GREATER</constant> refers to the failure and
  22. is used as key, and the message itself is used as value of the message array.
  23. </para>
  24. <para>
  25. You can retrieve all message templates from a validator by using the
  26. <methodname>getMessageTemplates()</methodname> method. It returns you the above array which
  27. contains all messages a validator could return in the case of a failed validation.
  28. </para>
  29. <programlisting language="php"><![CDATA[
  30. $validator = new Zend_Validate_GreaterThan();
  31. $messages = $validator->getMessageTemplates();
  32. ]]></programlisting>
  33. <para>
  34. Using the <methodname>setMessage()</methodname> method you can set another message to be
  35. returned in case of the specified failure.
  36. </para>
  37. <programlisting language="php"><![CDATA[
  38. $validator = new Zend_Validate_GreaterThan();
  39. $validator->setMessage('Please enter a lower value', Zend_Validate_GreaterThan::NOT_GREATER);
  40. ]]></programlisting>
  41. <para>
  42. The second parameter defines the failure which will be overridden. When you omit this
  43. parameter, then the given message will be set for all possible failures of this validator.
  44. </para>
  45. <sect2 id="zend.validate.messages.pretranslated">
  46. <title>Using pre-translated validation messages</title>
  47. <para>
  48. Zend Framework is shipped with more than 45 different validators with more than 200
  49. failure messages. It can be a tendious task to translate all of these messages. But for
  50. your convinience Zend Framework comes with already pre-translated validation messages.
  51. You can find them within the path <filename>/resources/languages</filename> in your
  52. Zend Framework installation.
  53. </para>
  54. <note>
  55. <title>Used path</title>
  56. <para>
  57. The resource files are outside of the library path because all of your translations
  58. should also be outside of this path.
  59. </para>
  60. </note>
  61. <para>
  62. So to translate all validation messages to german for example, all you have to do is to
  63. attach a translator to <classname>Zend_Validate</classname> using these resource files.
  64. </para>
  65. <programlisting language="php"><![CDATA[
  66. $translator = new Zend_Translate(
  67. 'array',
  68. '/resources/languages',
  69. $language,
  70. array('scan' => Zend_Locale::LOCALE_DIRECTORY)
  71. );
  72. Zend_Validate_Abstract::setDefaultTranslator($translator);
  73. ]]></programlisting>
  74. <note>
  75. <title>Used translation adapter</title>
  76. <para>
  77. As translation adapter Zend Framework choosed the array adapter. It is simple to
  78. edit and created very fast.
  79. </para>
  80. </note>
  81. <note>
  82. <title>Supported languages</title>
  83. <para>
  84. This feature is very young, so the amount of supported languages may not be
  85. complete. New languages will be added with each release. Additionally feel free to
  86. use the existing resource files to make your own translations.
  87. </para>
  88. <para>
  89. You could also use these resource files to rewrite existing translations. So you
  90. are not in need to create these files manually yourself.
  91. </para>
  92. </note>
  93. </sect2>
  94. <sect2 id="zend.validate.messages.limitation">
  95. <title>Limiter la taille d'un message de validation</title>
  96. <para>
  97. Il peut être nécessaire parfois de limiter la taille en caractères des messages d'erreur
  98. retournés. par exemple si une vue n'autorise que 100 caractères par ligne.
  99. <classname>Zend_Validate</classname> propose une telle option.
  100. </para>
  101. <para>
  102. La taille actuelle est
  103. <methodname>Zend_Validate::getMessageLength()</methodname>. -1 signifie que le message ne
  104. sera pas tronqué et entièrement retourné, c'est le comportement par défaut.
  105. </para>
  106. <para>
  107. Pour limiter la taille, utilisez
  108. <methodname>Zend_Validate::setMessageLength()</methodname>. Lorsque la taille excède cette valeur,
  109. le message sera alors tronqué et suivi de '<emphasis>...</emphasis>'.
  110. </para>
  111. <programlisting language="php"><![CDATA[
  112. Zend_Validate::setMessageLength(100);
  113. ]]></programlisting>
  114. <note>
  115. <title>Où ce paramètre est-il utilisé&#160;?</title>
  116. <para>
  117. La taille des messages affecte aussi les messages personnalisés enregistrés, dès
  118. que le validateur considéré étend <classname>Zend_Validate_Abstract</classname>.
  119. </para>
  120. </note>
  121. </sect2>
  122. </sect1>