-
Notifications
You must be signed in to change notification settings - Fork 343
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
Make error message in controller translatable. #522
Make error message in controller translatable. #522
Conversation
09aa317
to
ef6c7e0
Compare
ef6c7e0
to
205ab55
Compare
*/ | ||
protected $failedLoginMessage = 'Authentication failed. Please try again.'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this removed? If this property is kept, we can easily override this message which is the beauty of this module. :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@roelvanduijnhoven Suppose, the site I am developing is not multi-language based. In that case, if this property is kept, we can easily override the message by extending the controller(ofcourse). I don't need to worry about translation in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case you could now overwrite the getFailedLoginMessage
method.
But as I argued I think overwritting the controller is not the correct way to go. Whatsmore ZfcUser
comes packed with translation out-of-the-box. So I really think this property has no added value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But to be fare. Removing the property could be seen as a BC break. I'll reintroduce it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also i think that message should be configuable by the moduleOptions bu( that is siomething for an other PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also introduces unwanted BC break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stijnhau We cannot make everything in the world configurable using module options. ZfcUser is intended to be simple and extendible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What unwanted BC are you talking about? I just reintroduced the property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now it's fine
*/ | ||
protected function getFailedLoginMessage() | ||
{ | ||
$message =' Authentication failed. Please try again.'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of declaring message here, please keep it in a property
The PR is updated. Regarding the property: why would you want to override it or make it more configurable? If you want to change the text there is now a mechanism to do so: translation. Furthermore making the text a property does not enhance it's configurability I would say. It is a protected property without any getter or setter. Thus the only way of overriding would be to extend the class. The later being a strange choice for a controller. |
Thanks for your input! |
Sorry I rebased the commit so some commits are not associated with their lines anymore. Regarding the return value. What do you mean precisly? |
Is that return value in a setter realy needed? |
@stijnhau I just mimicked the existing code. But yeah, it is pretty common, and called fluent interface. |
in this case is isn't needed so. |
public function getTranslator() | ||
{ | ||
if (!$this->translator && $this->getServiceLocator()) { | ||
$this->setTranslator($this->getServiceLocator()->get('translator')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
translator
should be MvcTranslator
. See https://github.com/zendframework/zf2/blob/master/library/Zend/Mvc/Service/ServiceListenerFactory.php#L62. The alias translator
is defined in ZendSkeleton
Why we don't use the flashmessanger view helper in the login view and add the translator there? |
@ojhaujjwal PR updated. Thanks for feedback. |
you are welcome |
The latest version unintentionally changed behaviour (this error message is no longer translated), thus I would say this is a serious bug. What is the status of this one, that is keeping this from being merged? Also #520 unintentionally changed behaviour. So I would recon a 1.2.2. release after these two problems have been fixed would be the correct way forward. |
It seems the bug introduced in the last release will not be fixed. Or even spoken about.. I guess any effort put into ZfcUser is better spent migrating this module away out of our code base.. |
This commit is made to the master branch. @roelvanduijnhoven please don't use master as it's a work in progress. Instead use the tags. And if you want to do PR agains stable ZfcUser, please do the PR agains the 1.x branch. Thank you. |
Allright, thanks. What is the status of 2.0 and what is the estimated release date? |
@roelvanduijnhoven Good question! |
In the meantime I solved this by using reflection to set the property correctly. Register the following class as a delegator for the class ZfcUserControllerDecorator implements DelegatorFactoryInterface
{
public function createDelegatorWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName, $callback)
{
/** @var UserController $controller */
$controller = $callback();
$property = new \ReflectionProperty($controller, 'failedLoginMessage');
$property->setAccessible(true);
$property->setValue($controller, 'E-mailadres of wachtwoord onjuist');
return $controller;
}
} |
I think the idea by @wuethrich44 is much better! |
Why dont use just use translator in the view templates? |
These ideas revolve around touching source code in this package. This hack does not. |
How is using translator in the view a |
Agree with @ojhaujjwal. Translation should be handled in the view. |
At the moment the error message that is placed in the controller seems not to be translated.
The message is copied from the flash messenger into to the form messages. However the FormError renderer that is used by default does not translate messages. Hence no translation.
This PR fixes this by adding the
Translator
as an optional dependency of theUserController
. If present it is used to translate.