﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31461	Make it easier to customize ValidationError messages in contrib.auth.password_validation	Joey van Breukelen	Joey van Breukelen	"Goal: Make it easier to customize ValidationError messages in contrib.auth.password_validation
Problem: None of the gettext strings are defined in class variables or are wrapped by methods, making it hard change gettext in a subclass.
Suggested solution: Wrap gettext with a method so its easy to change in subclass.

Example:

{{{
class MinimumLengthValidator:
    # some code left out
    def validate(self, password, user=None):
        if len(password) < self.min_length:
            raise ValidationError(
                ngettext(
                    ""This password is too short. It must contain at least %(min_length)d character."",
                    ""This password is too short. It must contain at least %(min_length)d characters."",
                    self.min_length
                ),
                code='password_too_short',
                params={'min_length': self.min_length},
            )

}}}

Suggested change:

{{{
class MinimumLengthValidator:
    # some code left out
    def get_error_message(self):
        return ngettext(
            ""This password is too short. It must contain at least %(min_length)d character."",
            ""This password is too short. It must contain at least %(min_length)d characters."",
            self.min_length
        )
    
        if len(password) < self.min_length:
            raise ValidationError(
                self.get_error_message(),
                code='password_too_short',
                params={'min_length': self.min_length},
            )


class CustomMinimumLengthValidator(MinimumLengthValidator):
    def get_error_message(self):
        return ngettext(
            ""This password is too short. It must contain at least %(min_length)d character."",
            ""This password is too short. It must contain at least %(min_length)d characters."",
            self.min_length
        )

}}}


This will be similar to how get_help_text works on these classes:

{{{
class MinimumLengthValidator:
    # code left out
    def get_help_text(self):
        return ngettext(
            ""Your password must contain at least %(min_length)d character."",
            ""Your password must contain at least %(min_length)d characters."",
            self.min_length
        ) % {'min_length': self.min_length}
}}}

The problem can also be resolved by creating class variables with gettext_lazy, but this might get messy with plurals (which MinimumLengthValidator currently has) and would be a different pattern than the get_help_text method. 
"	Cleanup/optimization	closed	contrib.auth	3.0	Normal	wontfix			Unreviewed	0	0	0	0	1	0
