Hello Ralf,

> currently I use this code in a ListenerAggregate class to add the
> translations for validators:
> 
>       $baseDir = APPLICATION_ROOT . '/module/Application/language';
> 
>       $translator = Translator::factory(array(
>           'locale'                    => 'de',
>           'translation_file_patterns' => array(
>               array(
>                   'type'        => 'phpArray',
>                   'base_dir'    => $baseDir,
>                   'pattern'     => 'Zend_Validate.php',
>                   'text_domain' => 'default',
>               ),
>           )
>       ));
> 
>       AbstractValidator::setDefaultTranslator($translator);

I'm not so sure whether I should specify the translator statically. I've dug 
around in the code a bit and found the following:

* when adding inputs to the input filter using array specification, 
Zend\InputFilter\Factory::createInput() is invoked
* if a validators option is found in the array specification, 
Zend\InputFilter\Factory::createInput() iterates over the validator 
specifications
* for each validator specification, 
Zend\InputFilter\Factory::populateValidators() is called with the validator 
chain of the input as an argument
* if no validator chain exists, Zend\InputFilter\Input::getValidatorChain() 
will instantiate one, set and return it
* then, Zend\InputFilter\Factory::populateValidators() will call 
Zend\Validator\ValidatorChain::addByName() and while doing so, retrieve - and 
if the chain doesn't have one, create an instance of - a 
Zend\Validator\ValidatorPluginManager
* upon construction, Zend\Validator\ValidatorPluginManager adds an initialiser 
to itself, which should inject a translate service retrieved from the plugin 
manager itself into the validator

Problem is, my validators never have a translator injected into them.

Why, though, do I ask? What am I missing here?

> The problem I see with your gist is that I need to set the messages for
> every validator I usw. With AbstractValidator::setDefaultTranslator() I
> can set it a central point and I only need to overwrite such messages
> which are to technical and hard to understand for end users.

Actually, I'm just overriding a few messages I don't like to see, as otherwise 
the default message templates will be used.


Best regards,

Andreas
--
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com


Reply via email to