from django.contrib.auth.password_validation import validate_password from django.core.exceptions import ValidationError TRANSLATION_MAP = { "This password is too short. It must contain at least 8 characters.": "Hasło jest za krótkie. Musi mieć co najmniej 8 znaków.", "This password is too common.": "Hasło jest zbyt popularne.", "This password is entirely numeric.": "Hasło nie może składać się wyłącznie z cyfr.", "The password is too similar to the username.": "Hasło jest zbyt podobne do nazwy użytkownika.", "The password is too similar to the email address.": "Hasło jest zbyt podobne do adresu e-mail.", # dodaj więcej jeśli potrzeba } def validate_password_with_translation(password, user=None): try: validate_password(password, user) except ValidationError as e: translated_errors = [TRANSLATION_MAP.get(msg, msg) for msg in e.messages] raise ValidationError(translated_errors)