title: Zend Framework: Is it possible to override some of the validator error messages, when using built in translator?
body: <p>I've used validator errors customization example from this answer: <a href="https://stackoverflow.com/questions/4880076/custom-error-message-for-input-validators-using-the-array-syntax">https://stackoverflow.com/a/4881030/822947</a>, but I need to override some of translated errors with addValidator() or setMessage()/setMessages(). Examples below doesn't work (seems, built in translator has priority?)... How can I do it?</p>
  
  <pre><code>$field-&gt;addValidator ('Alpha', false, array ('messages' =&gt; array (Zend_Validate_Alpha::NOT_ALPHA =&gt; 'My msg')));
  
  $Alpha = new Zend_Validate_Alpha ();
  $Alpha-&gt;setDisableTranslator (true);
  $Alpha-&gt;setMessage ('My msg', Zend_Validate_Alpha::NOT_ALPHA);
  
  $Alpha-&gt;setMessages (array (Zend_Validate_Alpha::NOT_ALPHA  =&gt; 'My msg'));
  $field-&gt;addValidator ($Alpha);
  </code></pre>
  
  <p><strong>UPDATE</strong>
  The problem not in the way I add validator and set messages to it.</p>
  
  <p>My goal is to localize <i>all</i> error messages. But for <i>some</i> form fields I need to add more specific messages.</p>
  
  <p>For example, in my lang/translate.php I have common
  <code>Zend_Validate_Alpha::NOT_ALPHA =&gt; 'Value contains non alphabetic characters'</code>,</p>
  
  <p>but for name field I need more specific
  <code>Zend_Validate_Alpha::NOT_ALPHA =&gt; 'Field can contain only alphabetic characters and spaces'</code>,</p>
  
  <p>The problem is specific message ignored when I enable built in translator. So for example code</p>
  
  <pre><code>$form = new Zend_Form ();
  
  $validator = new Zend_Validate_Alpha ();
  $validator-&gt;setMessages (array (
      Zend_Validate_Alpha::NOT_ALPHA =&gt; 'xxx %value% x'
  ));
  
  $form-&gt;addElement ('text', 'digit', array (
      'validators' =&gt; array (
          $validator
      )
  ));
  
  $name = new Zend_Form_Element_Text ('name');
  $name-&gt;addValidator ('Alpha', true, array (
      'allowWhiteSpace' =&gt; true,
      'messages' =&gt; array
      (
          Zend_Validate_Alpha::NOT_ALPHA =&gt; 'my more specific localized msg',
      )
  ));
  
  $form-&gt;addElement ($name);
  
  $form-&gt;isValid (array (
      'digit' =&gt; '___',
      'name' =&gt; '___',
  ));
  
  Zend_Debug::dump ($form-&gt;getMessages ());
  </code></pre>
  
  <p>when translator disabled, I have</p>
  
  <pre><code>array(2) {
    'digit' =&gt;
    array(1) {
      'notAlpha' =&gt;
      string(9) "xxx ___ x"
    }
    'name' =&gt;
    array(1) {
      'notAlpha' =&gt;
      string(30) "my more specific localized msg"
    }
  }
  </code></pre>
  
  <p>when translator enabled, I have messages from lang/translate.php</p>
  
  <pre><code>array(2) {
    'digit' =&gt;
    array(1) {
      'notAlpha' =&gt;
      string(104) "common localized msg"
    }
    'name' =&gt;
    array(1) {
      'notAlpha' =&gt;
      string(104) "common localized msg"
    }
  }
  </code></pre>