Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Fix #28 - NotEmpty validation message cannot be localized #67

Conversation

$notEmpty = new NotEmpty();
$templates = $notEmpty->getOption('messageTemplates');
$message = $templates[NotEmpty::IS_EMPTY];
$translator = $notEmpty->getTranslator();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Translator will always be empty here because you're directly instantiating it. Try pulling it from the validator chain instead, add that will likely use the plugin manager, and thus have access to the translator.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I beg to differ. This actually works in a real application.

The test reproduces the issue with the configuration suggested in http://framework.zend.com/manual/current/en/modules/zend.validator.messages.html#using-pre-translated-validation-messages

I also have a functional test in a real world application that reproduces it exactly in the same way.

The translator will not be empty even in new instances, as long as Zend\Validator\AbstractValidator::setDefaultTranslator() is used;
I tried avoding the static method usage, but in my experience the ValidatorPluginManager does not work consistently and I ended up with the translator not being correctly injected.

I can change the new statement with a plugin() invocation from the validator chain, but the static method call will still be necessary.

@Maks3w
Copy link
Member

Maks3w commented Oct 10, 2015

Please take a look to #62

@stefanotorresi
Copy link
Contributor Author

@Maks3w it comes down to what version are you targeting with that PR. To me it looks like it's a bc break, while this PR is completely BC safe. Your call either way, as far as I'm concerned I have nothing more to add to this one, as I have addressed @weierophinney request to pull the validator from the plugin manager in the last commit.

@Slamdunk
Copy link
Contributor

So @Maks3w , is this PR going to be merged please?

You can tag this in a minor release, and then think about #62 for a future mid-release.
As a non-english-site user, our business apps really need this.

@Maks3w
Copy link
Member

Maks3w commented Nov 18, 2015

/fw @weierophinney

@weierophinney
Copy link
Member

@Maks3w Are you wanting me to review this one or #62?

@Maks3w
Copy link
Member

Maks3w commented Nov 18, 2015

@weierophinney #62 still being a PoC for future developments. I don't consider it enough stable. The point I forward this discussion to you is for assign you all the issues and PRs open about the translation of this message.

@weierophinney
Copy link
Member

@Maks3w Could you maybe curate a list for me?

@Maks3w
Copy link
Member

Maks3w commented Nov 18, 2015

@weierophinney I've updated the PR comment with a list of related issues/PRs

@johnnymallie
Copy link

Hi ! Any news about the release ? Looking forward to it :)

@jaapio
Copy link
Contributor

jaapio commented Mar 4, 2016

It would be very helpfull for us to have this merged. It provides a solution to a very common problem. I know this is not the ideal solution but it is a step forward in the right direction

@Slamdunk
Copy link
Contributor

Slamdunk commented Mar 4, 2016

🔔

@stefanotorresi
Copy link
Contributor Author

@weierophinney I think this is safe to merge for now, and then we can start working with a broader solution encompassing all the other related issues, but ultimately it's your call, of course :)
Let me know if you need me to change anything.

@weierophinney weierophinney added this to the 2.6.1 milestone Apr 7, 2016
@weierophinney weierophinney merged commit cf1f691 into zendframework:master Apr 7, 2016
weierophinney added a commit that referenced this pull request Apr 7, 2016
…e-i18n

Fix #28 - NotEmpty validation message cannot be localized
weierophinney added a commit that referenced this pull request Apr 7, 2016
weierophinney added a commit that referenced this pull request Apr 7, 2016
weierophinney added a commit that referenced this pull request Apr 7, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants