zendframework / zend-validator

Validator component from Zend Framework
BSD 3-Clause "New" or "Revised" License
181 stars 136 forks source link

What is the point of Zend\Validator\Translator\TranslatorInterface? #48

Closed RalfEggert closed 8 years ago

RalfEggert commented 8 years ago

I am just trying to internationalize my Zend\Expressive application and stumbled upon the Zend\Validator\Translator\TranslatorInterface interface, which is checked when I use Zend\Validator\AbstractValidator::setDefaultTranslator() method. I learned now that I cannot use a normal Zend\I18n\Translator\Translator instance. In a Zend\Mvc scenario this issue is solved by the Zend\Mvc\I18n\Translator which uses an Zend\I18n\Translator\Translator instance and implements the Zend\Validator\Translator\TranslatorInterface interface.

It doesn't feel right to use the Zend\Mvc\I18n\Translator within my Zend\Expressive application.

It doesn't feel right to implement a Zend\Expressive\I18n\Translator similar to the Zend\Mvc\I18n\Translator.

What a mess.

So, what is the point of the Zend\Validator\Translator\TranslatorInterface in the first place? The Zend\I18n\Translator\TranslatorInterface has the same method signature for the translate() method except it adds another translatePlural() method to the interface. Why not split Zend\I18n\Translator\TranslatorInterface into two interfaces and kick Zend\Validator\Translator\TranslatorInterface?

Are there any plans to tidy this up? Anyway what about the plans to make the validators stateless and extract the translation part from it? I think both is really needed for a ZF3 release to make translation and validation usable within a Zend\Expressive application.

Maks3w commented 8 years ago

Segregation of Interfaces and remove the i18n dependency

RalfEggert commented 8 years ago

Please clarify! I don't get it.

Maks3w commented 8 years ago

https://github.com/zendframework/zf2/commit/4bf9a344ef7246e29728f5571b55c5ad26244a5a

RalfEggert commented 8 years ago

So the dependency to Zend\I18n was removed to the costs of a Zend\Mvc dependency?

Maks3w commented 8 years ago

Mvc offers a bridge for both interfaces but i18n neither validator depends of Mvc.

RalfEggert commented 8 years ago

So in consequence I need to build my own bridge if I want to use the same Translator instance for I18n view helpers and validators if I am in an Zend\Expressive environment and I don't want to use the MVC bridge?

If yes, it still feels kind of awkward...

Maks3w commented 8 years ago

This may suffer changes in future releases #24

RalfEggert commented 8 years ago

I love the idea of stateless validators and keeping the whole translation stuff outside of the validator.