From 9898c4ae02e455896c6e53a10891dc1b3a334a80 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Fri, 25 Nov 2005 02:32:37 +0000 Subject: [PATCH] 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 --- django/core/formfields.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/django/core/formfields.py b/django/core/formfields.py index fae239987a..78fd044815 100644 --- a/django/core/formfields.py +++ b/django/core/formfields.py @@ -2,6 +2,7 @@ from django.core import validators 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 @@ class Manipulator: 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 @@ class Manipulator: 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 @@ class TextField(FormField): 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 @@ class SelectField(FormField): 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 @@ class RadioSelectField(FormField): 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 @@ class SelectMultipleField(SelectField): 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 @@ class FileUploadField(FormField): 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 '' % \ @@ -549,7 +551,7 @@ class SmallIntegerField(IntegerField): 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 @@ class PositiveIntegerField(IntegerField): 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 @@ class PositiveSmallIntegerField(IntegerField): 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=[]):