vt-middleware / passay

Password policy enforcement for Java.
http://www.passay.org
Other
275 stars 63 forks source link

Message Customization: Missing possibility to translate "contains", "starts with" and "ends with" #139

Closed tacaheca closed 1 year ago

tacaheca commented 1 year ago

For some i18n properties placeholders are replaced with verbs defined by MatchBehaviours (if I interpreted the code correctly). e.g. Original properties: ILLEGAL_CHAR=Password %2$s the illegal character '%1$s'. ALLOWED_CHAR=Password %2$s the illegal character '%1$s'. German properties: ILLEGAL_CHAR=Passwort %2$s das unzulässige Zeichen '%1$s'. ALLOWED_CHAR=Passwort %2$s das unzulässige Zeichen '%1$s'.

Translated text: Passwort contains das unzulässige Zeichen 'a'

I would also like to be able to translate "contains" to have the correct translation. ('Passwort enthält das ungültige Zeichen 'a'.)

dfish3r commented 1 year ago

If you're using a single rule that leverages MatchBehavior then you can set the message you want in the properties:

# This rule is configured with MatchBehavior#Contains
ILLEGAL_CHAR=Passwort enthält das unzulässige Zeichen '%1$s'.

Obviously this breaks down if you've configured multiple instances of any of the following:

I'll have to give some thought as to how to internationalize the MatchBehavior enum.

dfish3r commented 1 year ago

Pushed a new snapshot which allows defining custom messages for rules that use MatchBehavior e.g.

Please confirm this change resolves your issue.

tacaheca commented 1 year ago

Pushed a new snapshot which allows defining custom messages for rules that use MatchBehavior e.g.

* ILLEGAL_CHAR.STARTS_WITH=

* ILLEGAL_CHAR.CONTAINS=

* ILLEGAL_CHAR.ENDS_WITH=

Please confirm this change resolves your issue.

Sorry for answering late. This looks great. Thank you very much.