mirror of https://github.com/django/django.git
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
This commit is contained in:
parent
c60e323e5d
commit
9898c4ae02
|
@ -2,6 +2,7 @@ from django.core import validators
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
from django.conf.settings import DEFAULT_CHARSET
|
from django.conf.settings import DEFAULT_CHARSET
|
||||||
|
from django.utils.translation import gettext_lazy, ngettext
|
||||||
|
|
||||||
FORM_FIELD_ID_PREFIX = 'id_'
|
FORM_FIELD_ID_PREFIX = 'id_'
|
||||||
|
|
||||||
|
@ -23,7 +24,7 @@ class Manipulator:
|
||||||
for field in self.fields:
|
for field in self.fields:
|
||||||
if field.field_name == field_name:
|
if field.field_name == field_name:
|
||||||
return field
|
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):
|
def __delitem__(self, field_name):
|
||||||
"Deletes the field with the given field name; raises KeyError on failure"
|
"Deletes the field with the given field name; raises KeyError on failure"
|
||||||
|
@ -55,7 +56,7 @@ class Manipulator:
|
||||||
errors = {}
|
errors = {}
|
||||||
for field in self.fields:
|
for field in self.fields:
|
||||||
if field.is_required and not new_data.get(field.field_name, False):
|
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
|
continue
|
||||||
try:
|
try:
|
||||||
validator_list = field.validator_list
|
validator_list = field.validator_list
|
||||||
|
@ -237,11 +238,12 @@ class TextField(FormField):
|
||||||
|
|
||||||
def isValidLength(self, data, form):
|
def isValidLength(self, data, form):
|
||||||
if data and self.maxlength and len(data.decode(DEFAULT_CHARSET)) > self.maxlength:
|
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):
|
def hasNoNewlines(self, data, form):
|
||||||
if data and '\n' in data:
|
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):
|
def render(self, data):
|
||||||
if data is None:
|
if data is None:
|
||||||
|
@ -334,7 +336,7 @@ class SelectField(FormField):
|
||||||
str_data = str(data)
|
str_data = str(data)
|
||||||
str_choices = [str(item[0]) for item in self.choices]
|
str_choices = [str(item[0]) for item in self.choices]
|
||||||
if str_data not in str_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):
|
class NullSelectField(SelectField):
|
||||||
"This SelectField converts blank fields to None"
|
"This SelectField converts blank fields to None"
|
||||||
|
@ -403,7 +405,7 @@ class RadioSelectField(FormField):
|
||||||
str_data = str(data)
|
str_data = str(data)
|
||||||
str_choices = [str(item[0]) for item in self.choices]
|
str_choices = [str(item[0]) for item in self.choices]
|
||||||
if str_data not in str_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):
|
class NullBooleanField(SelectField):
|
||||||
"This SelectField provides 'Yes', 'No' and 'Unknown', mapping results to True, False or None"
|
"This SelectField provides 'Yes', 'No' and 'Unknown', mapping results to True, False or None"
|
||||||
|
@ -441,7 +443,7 @@ class SelectMultipleField(SelectField):
|
||||||
str_choices = [str(item[0]) for item in self.choices]
|
str_choices = [str(item[0]) for item in self.choices]
|
||||||
for val in map(str, field_data):
|
for val in map(str, field_data):
|
||||||
if val not in str_choices:
|
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):
|
def html2python(data):
|
||||||
if data is None:
|
if data is None:
|
||||||
|
@ -497,7 +499,7 @@ class FileUploadField(FormField):
|
||||||
|
|
||||||
def isNonEmptyFile(self, field_data, all_data):
|
def isNonEmptyFile(self, field_data, all_data):
|
||||||
if not field_data['content']:
|
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):
|
def render(self, data):
|
||||||
return '<input type="file" id="%s" class="v%s" name="%s" />' % \
|
return '<input type="file" id="%s" class="v%s" name="%s" />' % \
|
||||||
|
@ -549,7 +551,7 @@ class SmallIntegerField(IntegerField):
|
||||||
|
|
||||||
def isSmallInteger(self, field_data, all_data):
|
def isSmallInteger(self, field_data, all_data):
|
||||||
if not -32768 <= int(field_data) <= 32767:
|
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):
|
class PositiveIntegerField(IntegerField):
|
||||||
def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=[]):
|
def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=[]):
|
||||||
|
@ -558,7 +560,7 @@ class PositiveIntegerField(IntegerField):
|
||||||
|
|
||||||
def isPositive(self, field_data, all_data):
|
def isPositive(self, field_data, all_data):
|
||||||
if int(field_data) < 0:
|
if int(field_data) < 0:
|
||||||
raise validators.CriticalValidationError, "Enter a positive number."
|
raise validators.CriticalValidationError, _("Enter a positive number.")
|
||||||
|
|
||||||
class PositiveSmallIntegerField(IntegerField):
|
class PositiveSmallIntegerField(IntegerField):
|
||||||
def __init__(self, field_name, length=5, maxlength=None, is_required=False, validator_list=[]):
|
def __init__(self, field_name, length=5, maxlength=None, is_required=False, validator_list=[]):
|
||||||
|
@ -567,7 +569,7 @@ class PositiveSmallIntegerField(IntegerField):
|
||||||
|
|
||||||
def isPositiveSmall(self, field_data, all_data):
|
def isPositiveSmall(self, field_data, all_data):
|
||||||
if not 0 <= int(field_data) <= 32767:
|
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):
|
class FloatField(TextField):
|
||||||
def __init__(self, field_name, max_digits, decimal_places, is_required=False, validator_list=[]):
|
def __init__(self, field_name, max_digits, decimal_places, is_required=False, validator_list=[]):
|
||||||
|
|
Loading…
Reference in New Issue