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

Make error message in controller translatable. #522

Conversation

roelvanduijnhoven
Copy link
Contributor

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 the UserController. If present it is used to translate.

*/
protected $failedLoginMessage = 'Authentication failed. Please try again.';
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link

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

Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Now it's fine

Roel van Duijnhoven added 2 commits September 4, 2014 15:35
*/
protected function getFailedLoginMessage()
{
$message =' Authentication failed. Please try again.';
Copy link
Contributor

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

@roelvanduijnhoven
Copy link
Contributor Author

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.

@roelvanduijnhoven
Copy link
Contributor Author

Thanks for your input!

@roelvanduijnhoven
Copy link
Contributor Author

Sorry I rebased the commit so some commits are not associated with their lines anymore.

Regarding the return value. What do you mean precisly?

@stijnhau
Copy link

stijnhau commented Sep 4, 2014

Is that return value in a setter realy needed?
A setter that have a return value seems kinda strange to me.

@roelvanduijnhoven
Copy link
Contributor Author

@stijnhau I just mimicked the existing code. But yeah, it is pretty common, and called fluent interface.

@stijnhau
Copy link

stijnhau commented Sep 4, 2014

in this case is isn't needed so.
BNut i usnderstand why u added it because so that they all are the same.

public function getTranslator()
{
if (!$this->translator && $this->getServiceLocator()) {
$this->setTranslator($this->getServiceLocator()->get('translator'));
Copy link
Contributor

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

@fabwu
Copy link

fabwu commented Sep 4, 2014

Why we don't use the flashmessanger view helper in the login view and add the translator there?

@roelvanduijnhoven
Copy link
Contributor Author

@ojhaujjwal PR updated. Thanks for feedback.

@ojhaujjwal
Copy link
Contributor

you are welcome

@roelvanduijnhoven
Copy link
Contributor Author

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.

@roelvanduijnhoven
Copy link
Contributor Author

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..

@Danielss89
Copy link
Member

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.

@roelvanduijnhoven
Copy link
Contributor Author

Allright, thanks.

What is the status of 2.0 and what is the estimated release date?

@ojhaujjwal
Copy link
Contributor

@roelvanduijnhoven Good question!

@roelvanduijnhoven
Copy link
Contributor Author

In the meantime I solved this by using reflection to set the property correctly.

Register the following class as a delegator for the ZfcUser controller:

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;
    }
}

@ojhaujjwal
Copy link
Contributor

I think the idea by @wuethrich44 is much better!

@ojhaujjwal
Copy link
Contributor

Why dont use just use translator in the view templates?

@roelvanduijnhoven
Copy link
Contributor Author

These ideas revolve around touching source code in this package. This hack does not.

@ojhaujjwal
Copy link
Contributor

How is using translator in the view a hack? IMO translator lies in View of MVC!

@Danielss89
Copy link
Member

Agree with @ojhaujjwal. Translation should be handled in the view.
POedit won't catch this though, so maybe we should create a Translate file, which just list all of the translation that can't be catched?

@Danielss89 Danielss89 closed this Dec 12, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants