Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 authored November 25, 2005

Showing 1 changed file with 13 additions and 11 deletions. Show diff stats Hide diff stats

  1. 24  django/core/formfields.py
24  django/core/formfields.py
@@ -2,6 +2,7 @@
2 2
 from django.core.exceptions import PermissionDenied
3 3
 from django.utils.html import escape
4 4
 from django.conf.settings import DEFAULT_CHARSET
  5
+from django.utils.translation import gettext_lazy, ngettext
5 6
 
6 7
 FORM_FIELD_ID_PREFIX = 'id_'
7 8
 
@@ -23,7 +24,7 @@ def __getitem__(self, field_name):
23 24
         for field in self.fields:
24 25
             if field.field_name == field_name:
25 26
                 return field
26  
-        raise KeyError, "Field %s not found" % field_name
  27
+        raise KeyError, "Field %s not found\n%s" % (field_name, repr(self.fields))
27 28
 
28 29
     def __delitem__(self, field_name):
29 30
         "Deletes the field with the given field name; raises KeyError on failure"
@@ -55,7 +56,7 @@ def get_validation_errors(self, new_data):
55 56
         errors = {}
56 57
         for field in self.fields:
57 58
             if field.is_required and not new_data.get(field.field_name, False):
58  
-                errors.setdefault(field.field_name, []).append('This field is required.')
  59
+                errors.setdefault(field.field_name, []).append(gettext_lazy('This field is required.'))
59 60
                 continue
60 61
             try:
61 62
                 validator_list = field.validator_list
@@ -237,11 +238,12 @@ def __init__(self, field_name, length=30, maxlength=None, is_required=False, val
237 238
 
238 239
     def isValidLength(self, data, form):
239 240
         if data and self.maxlength and len(data.decode(DEFAULT_CHARSET)) > self.maxlength:
240  
-            raise validators.ValidationError, "Ensure your text is less than %s characters." % self.maxlength
  241
+            raise validators.ValidationError, ngettext("Ensure your text is less than %s character.",
  242
+                "Ensure your text is less than %s characters.", self.maxlength) % self.maxlength
241 243
 
242 244
     def hasNoNewlines(self, data, form):
243 245
         if data and '\n' in data:
244  
-            raise validators.ValidationError, "Line breaks are not allowed here."
  246
+            raise validators.ValidationError, _("Line breaks are not allowed here.")
245 247
 
246 248
     def render(self, data):
247 249
         if data is None:
@@ -334,7 +336,7 @@ def isValidChoice(self, data, form):
334 336
         str_data = str(data)
335 337
         str_choices = [str(item[0]) for item in self.choices]
336 338
         if str_data not in str_choices:
337  
-            raise validators.ValidationError, "Select a valid choice; '%s' is not in %s." % (str_data, str_choices)
  339
+            raise validators.ValidationError, _("Select a valid choice; '%(data)s' is not in %(choices)s.") % {'data': str_data, 'choices': str_choices}
338 340
 
339 341
 class NullSelectField(SelectField):
340 342
     "This SelectField converts blank fields to None"
@@ -403,7 +405,7 @@ def isValidChoice(self, data, form):
403 405
         str_data = str(data)
404 406
         str_choices = [str(item[0]) for item in self.choices]
405 407
         if str_data not in str_choices:
406  
-            raise validators.ValidationError, "Select a valid choice; '%s' is not in %s." % (str_data, str_choices)
  408
+            raise validators.ValidationError, _("Select a valid choice; '%(data)s' is not in %(choices)s.") % {'data':str_data, 'choices':str_choices}
407 409
 
408 410
 class NullBooleanField(SelectField):
409 411
     "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):
441 443
         str_choices = [str(item[0]) for item in self.choices]
442 444
         for val in map(str, field_data):
443 445
             if val not in str_choices:
444  
-                raise validators.ValidationError, "Select a valid choice; '%s' is not in %s." % (val, str_choices)
  446
+                raise validators.ValidationError, _("Select a valid choice; '%(data)s' is not in %(choices)s.") % {'data':val, 'choices':str_choices}
445 447
 
446 448
     def html2python(data):
447 449
         if data is None:
@@ -497,7 +499,7 @@ def __init__(self, field_name, is_required=False, validator_list=[]):
497 499
 
498 500
     def isNonEmptyFile(self, field_data, all_data):
499 501
         if not field_data['content']:
500  
-            raise validators.CriticalValidationError, "The submitted file is empty."
  502
+            raise validators.CriticalValidationError, _("The submitted file is empty.")
501 503
 
502 504
     def render(self, data):
503 505
         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
549 551
 
550 552
     def isSmallInteger(self, field_data, all_data):
551 553
         if not -32768 <= int(field_data) <= 32767:
552  
-            raise validators.CriticalValidationError, "Enter a whole number between -32,768 and 32,767."
  554
+            raise validators.CriticalValidationError, _("Enter a whole number between -32,768 and 32,767.")
553 555
 
554 556
 class PositiveIntegerField(IntegerField):
555 557
     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
558 560
 
559 561
     def isPositive(self, field_data, all_data):
560 562
         if int(field_data) < 0:
561  
-            raise validators.CriticalValidationError, "Enter a positive number."
  563
+            raise validators.CriticalValidationError, _("Enter a positive number.")
562 564
 
563 565
 class PositiveSmallIntegerField(IntegerField):
564 566
     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
567 569
 
568 570
     def isPositiveSmall(self, field_data, all_data):
569 571
         if not 0 <= int(field_data) <= 32767:
570  
-            raise validators.CriticalValidationError, "Enter a whole number between 0 and 32,767."
  572
+            raise validators.CriticalValidationError, _("Enter a whole number between 0 and 32,767.")
571 573
 
572 574
 class FloatField(TextField):
573 575
     def __init__(self, field_name, max_digits, decimal_places, is_required=False, validator_list=[]):

0 notes on commit 9898c4a

Please sign in to comment.
Something went wrong with that request. Please try again.