Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added translation strings to core/formfields.py. Taken from new-admin.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1422 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 9898c4ae02e455896c6e53a10891dc1b3a334a80 1 parent c60e323
Adrian Holovaty adrianholovaty authored
Showing with 13 additions and 11 deletions.
  1. +13 −11 django/core/formfields.py
24 django/core/formfields.py
View
@@ -2,6 +2,7 @@
from django.core.exceptions import PermissionDenied
from django.utils.html import escape
from django.conf.settings import DEFAULT_CHARSET
+from django.utils.translation import gettext_lazy, ngettext
FORM_FIELD_ID_PREFIX = 'id_'
@@ -23,7 +24,7 @@ def __getitem__(self, field_name):
for field in self.fields:
if field.field_name == field_name:
return field
- raise KeyError, "Field %s not found" % field_name
+ raise KeyError, "Field %s not found\n%s" % (field_name, repr(self.fields))
def __delitem__(self, field_name):
"Deletes the field with the given field name; raises KeyError on failure"
@@ -55,7 +56,7 @@ def get_validation_errors(self, new_data):
errors = {}
for field in self.fields:
if field.is_required and not new_data.get(field.field_name, False):
- errors.setdefault(field.field_name, []).append('This field is required.')
+ errors.setdefault(field.field_name, []).append(gettext_lazy('This field is required.'))
continue
try:
validator_list = field.validator_list
@@ -237,11 +238,12 @@ def __init__(self, field_name, length=30, maxlength=None, is_required=False, val
def isValidLength(self, data, form):
if data and self.maxlength and len(data.decode(DEFAULT_CHARSET)) > self.maxlength:
- raise validators.ValidationError, "Ensure your text is less than %s characters." % self.maxlength
+ raise validators.ValidationError, ngettext("Ensure your text is less than %s character.",
+ "Ensure your text is less than %s characters.", self.maxlength) % self.maxlength
def hasNoNewlines(self, data, form):
if data and '\n' in data:
- raise validators.ValidationError, "Line breaks are not allowed here."
+ raise validators.ValidationError, _("Line breaks are not allowed here.")
def render(self, data):
if data is None:
@@ -334,7 +336,7 @@ def isValidChoice(self, data, form):
str_data = str(data)
str_choices = [str(item[0]) for item in self.choices]
if str_data not in str_choices:
- raise validators.ValidationError, "Select a valid choice; '%s' is not in %s." % (str_data, str_choices)
+ raise validators.ValidationError, _("Select a valid choice; '%(data)s' is not in %(choices)s.") % {'data': str_data, 'choices': str_choices}
class NullSelectField(SelectField):
"This SelectField converts blank fields to None"
@@ -403,7 +405,7 @@ def isValidChoice(self, data, form):
str_data = str(data)
str_choices = [str(item[0]) for item in self.choices]
if str_data not in str_choices:
- raise validators.ValidationError, "Select a valid choice; '%s' is not in %s." % (str_data, str_choices)
+ raise validators.ValidationError, _("Select a valid choice; '%(data)s' is not in %(choices)s.") % {'data':str_data, 'choices':str_choices}
class NullBooleanField(SelectField):
"This SelectField provides 'Yes', 'No' and 'Unknown', mapping results to True, False or None"
@@ -441,7 +443,7 @@ def isValidChoice(self, field_data, all_data):
str_choices = [str(item[0]) for item in self.choices]
for val in map(str, field_data):
if val not in str_choices:
- raise validators.ValidationError, "Select a valid choice; '%s' is not in %s." % (val, str_choices)
+ raise validators.ValidationError, _("Select a valid choice; '%(data)s' is not in %(choices)s.") % {'data':val, 'choices':str_choices}
def html2python(data):
if data is None:
@@ -497,7 +499,7 @@ def __init__(self, field_name, is_required=False, validator_list=[]):
def isNonEmptyFile(self, field_data, all_data):
if not field_data['content']:
- raise validators.CriticalValidationError, "The submitted file is empty."
+ raise validators.CriticalValidationError, _("The submitted file is empty.")
def render(self, data):
return '<input type="file" id="%s" class="v%s" name="%s" />' % \
@@ -549,7 +551,7 @@ def __init__(self, field_name, length=5, maxlength=5, is_required=False, validat
def isSmallInteger(self, field_data, all_data):
if not -32768 <= int(field_data) <= 32767:
- raise validators.CriticalValidationError, "Enter a whole number between -32,768 and 32,767."
+ raise validators.CriticalValidationError, _("Enter a whole number between -32,768 and 32,767.")
class PositiveIntegerField(IntegerField):
def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=[]):
@@ -558,7 +560,7 @@ def __init__(self, field_name, length=10, maxlength=None, is_required=False, val
def isPositive(self, field_data, all_data):
if int(field_data) < 0:
- raise validators.CriticalValidationError, "Enter a positive number."
+ raise validators.CriticalValidationError, _("Enter a positive number.")
class PositiveSmallIntegerField(IntegerField):
def __init__(self, field_name, length=5, maxlength=None, is_required=False, validator_list=[]):
@@ -567,7 +569,7 @@ def __init__(self, field_name, length=5, maxlength=None, is_required=False, vali
def isPositiveSmall(self, field_data, all_data):
if not 0 <= int(field_data) <= 32767:
- raise validators.CriticalValidationError, "Enter a whole number between 0 and 32,767."
+ raise validators.CriticalValidationError, _("Enter a whole number between 0 and 32,767.")
class FloatField(TextField):
def __init__(self, field_name, max_digits, decimal_places, is_required=False, validator_list=[]):
Please sign in to comment.
Something went wrong with that request. Please try again.