How could we create a translation to validate error messages in the zend framework?

how could we create translated validation error messages based on zend?

could anyone give an example?

thank

+2


a source to share


2 answers


From ZF Manual Zend_Validate

to Verification Messages

  $validator = new Zend_Validate_GreaterThan();
  $validator->setMessage('Please enter a lower value', 
                         Zend_Validate_GreaterThan::NOT_GREATER);

      

And:



Zend Framework comes with over 45 different validators with over 200 error messages. It can be challenging to translate all of these messages. But for your convenience, Zend Framework comes with pre-translated validation messages. You can find them along the way /resources/languages

in your Zend Framework installation. [...]
Therefore, to translate all validation messages into German, all you have to do is attach the translator to Zend_Validate

using these resource files.

  $translator = new Zend_Translate(
      'array',
      '/resources/languages',
      $language,
      array('scan' => Zend_Locale::LOCALE_DIRECTORY)
  );
  Zend_Validate_Abstract::setDefaultTranslator($translator);

      

Of course, you can also provide your own translations. All you have to do is make them available to the translation adapter. Basically, you just swap the part shown above for your own path.

+7


a source


I just want to improve a little on the answer from Gordon: working example

$translator = new Zend_Translate(
    'array',
    'resources/languages',  // you need to copy the resources folder
                            // (from your Zend Framework installation)
                            // in the application folder 

    'it', // 'it' for italian, 'fr' for french, etc. 
          // Just look at the directories

    // Zend_Translate, NOT Zend_Locale
    array(
        'scan' => Zend_Translate::LOCALE_DIRECTORY
    )
);

Zend_Validate_Abstract::setDefaultTranslator($translator);

      



Hooray! Bruno

+1


a source







All Articles