Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple Validator from Translation component #15714

Closed
dawehner opened this issue Sep 7, 2015 · 9 comments
Closed

Decouple Validator from Translation component #15714

dawehner opened this issue Sep 7, 2015 · 9 comments

Comments

@dawehner
Copy link
Contributor

dawehner commented Sep 7, 2015

Hi.

Some people are wondering why the validator component needs to depend on the translation component and instead could be decoupled?

@dawehner
Copy link
Contributor Author

dawehner commented Sep 7, 2015

@stof
Copy link
Member

stof commented Sep 7, 2015

Well, violation constraints are returned translated already (since 2.2). This is why there is a dependency. Previously, there was 2 different ways to access the violation message depending on whether you wanted to use the translation system or no (and 2 different way to build violations depending on whether you wanted to make them compatible with the usage of translations or no)

@fabpot
Copy link
Member

fabpot commented Sep 7, 2015

see #6189 and #6137 as well.

@linaori
Copy link
Contributor

linaori commented Sep 9, 2015

Maybe the validator component could have it's own interfaces for it and have a recommended implementation by using the Symfony translations via adapters? Especially when used as component I think this dependency should not be a require, but suggest.

@dawehner
Copy link
Contributor Author

dawehner commented Sep 9, 2015

Note: Drupal is using now a pretty interesting trick.

We provide the TranslationInterface in its own folder as part of the Drupal project (together with the LICENSE file) and use a "replace" entry in composer.json to trick composer. Actually something like that could be done as hack for the validator as well, but I agree separating the interface in its own package would be better

@TomasVotruba
Copy link
Contributor

@dawehner 👍

@dawehner
Copy link
Contributor Author

And we realized that this was a horrible idea, because noone else is actually able to depend on a package which actually depend on the translation component and we reverted that.

@HadesArchitect
Copy link
Contributor

@dawehner Very nice idea. Also thought about it a lot.

@nicolas-grekas
Copy link
Member

Should be finally solved by #28210 (ping @alexpott also.)

@fabpot fabpot closed this as completed Sep 3, 2018
fabpot added a commit that referenced this issue Sep 3, 2018
…uple symfony/validator from symfony/translation (nicolas-grekas)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[Contracts] Add Translation\TranslatorInterface + decouple symfony/validator from symfony/translation

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #15714, #18930
| License       | MIT
| Doc PR        | -

Let's decouple Validator from Translation component \o/!

TODO:
- [x] add `TranslatorInterface`, deprecate it from Translation
- [x] add `TranslatorTrait`, deprecating `MessageSelector`, `Internal` and `PluralizationRules`
- [x] deprecate `ValidatorBuilderInterface(LegacyTranslatorInterface)`
- [x] inject a new `identity_translator` into `translator.formatter.default`, deprecate `translator.selector`
- [x] copy tests in the Contracts namespace to ensure the `TranslatorTrait` behaves properly
- [x] figure out a way to keep throwing `InvalidArgumentException` from the component
- [x] update UPGRADING and CHANGELOG files
- [x] polish the deprecation layer (ensure all needed runtime deprecations are here)

Reviews welcome already.

Commits
-------

064e369 [Contracts] Add Translation\TranslatorInterface + decouple symfony/validator from symfony/translation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants