1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fixed #19034 -- Added proper i18n pluralization for max/min length validation messages

This was made possible by commit 3f1a0c0040. Thanks Evil Clay
for the report and Alexey Boriskin his work on the ticket.
This commit is contained in:
Claude Paroz
2013-01-30 21:29:39 +01:00
parent c8c7cdc8f8
commit fc8efc2d9e
2 changed files with 14 additions and 5 deletions

View File

@@ -7,7 +7,7 @@ except ImportError: # Python 2
from urlparse import urlsplit, urlunsplit
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext_lazy as _, ungettext_lazy
from django.utils.encoding import force_text
from django.utils.ipv6 import is_valid_ipv6_address
from django.utils import six
@@ -209,12 +209,18 @@ class MinValueValidator(BaseValidator):
class MinLengthValidator(BaseValidator):
compare = lambda self, a, b: a < b
clean = lambda self, x: len(x)
message = _('Ensure this value has at least %(limit_value)d characters (it has %(show_value)d).')
message = ungettext_lazy(
'Ensure this value has at least %(limit_value)d character (it has %(show_value)d).',
'Ensure this value has at least %(limit_value)d characters (it has %(show_value)d).',
'limit_value')
code = 'min_length'
class MaxLengthValidator(BaseValidator):
compare = lambda self, a, b: a > b
clean = lambda self, x: len(x)
message = _('Ensure this value has at most %(limit_value)d characters (it has %(show_value)d).')
message = ungettext_lazy(
'Ensure this value has at most %(limit_value)d character (it has %(show_value)d).',
'Ensure this value has at most %(limit_value)d characters (it has %(show_value)d).',
'limit_value')
code = 'max_length'