Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

For readability, use _() as an alias to mark translatable strings.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6642 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 2184248c056a6d341ad815f1145406eb99ddbf40 1 parent 4e8864a
Malcolm Tredinnick authored November 04, 2007

Showing 1 changed file with 36 additions and 34 deletions. Show diff stats Hide diff stats

  1. 70  django/newforms/fields.py
70  django/newforms/fields.py
@@ -16,7 +16,7 @@
16 16
 except NameError:
17 17
     from sets import Set as set
18 18
 
19  
-from django.utils.translation import ugettext_lazy
  19
+from django.utils.translation import ugettext_lazy as _
20 20
 from django.utils.encoding import StrAndUnicode, smart_unicode
21 21
 
22 22
 from util import ErrorList, ValidationError
@@ -42,8 +42,8 @@ class Field(object):
42 42
     widget = TextInput # Default widget to use when rendering this type of Field.
43 43
     hidden_widget = HiddenInput # Default widget to use when rendering this as "hidden".
44 44
     default_error_messages = {
45  
-        'required': ugettext_lazy(u'This field is required.'),
46  
-        'invalid': ugettext_lazy(u'Enter a valid value.'),
  45
+        'required': _(u'This field is required.'),
  46
+        'invalid': _(u'Enter a valid value.'),
47 47
     }
48 48
 
49 49
     # Tracks each time a Field instance is created. Used to retain order.
@@ -87,11 +87,13 @@ def __init__(self, required=True, widget=None, label=None, initial=None,
87 87
 
88 88
     def _build_error_messages(self, extra_error_messages):
89 89
         error_messages = {}
  90
+
90 91
         def get_default_error_messages(klass):
91 92
             for base_class in klass.__bases__:
92 93
                 get_default_error_messages(base_class)
93 94
             if hasattr(klass, 'default_error_messages'):
94 95
                 error_messages.update(klass.default_error_messages)
  96
+
95 97
         get_default_error_messages(self.__class__)
96 98
         if extra_error_messages:
97 99
             error_messages.update(extra_error_messages)
@@ -124,8 +126,8 @@ def __deepcopy__(self, memo):
124 126
 
125 127
 class CharField(Field):
126 128
     default_error_messages = {
127  
-        'max_length': ugettext_lazy(u'Ensure this value has at most %(max)d characters (it has %(length)d).'),
128  
-        'min_length': ugettext_lazy(u'Ensure this value has at least %(min)d characters (it has %(length)d).'),
  129
+        'max_length': _(u'Ensure this value has at most %(max)d characters (it has %(length)d).'),
  130
+        'min_length': _(u'Ensure this value has at least %(min)d characters (it has %(length)d).'),
129 131
     }
130 132
 
131 133
     def __init__(self, max_length=None, min_length=None, *args, **kwargs):
@@ -152,9 +154,9 @@ def widget_attrs(self, widget):
152 154
 
153 155
 class IntegerField(Field):
154 156
     default_error_messages = {
155  
-        'invalid': ugettext_lazy(u'Enter a whole number.'),
156  
-        'max_value': ugettext_lazy(u'Ensure this value is less than or equal to %s.'),
157  
-        'min_value': ugettext_lazy(u'Ensure this value is greater than or equal to %s.'),
  157
+        'invalid': _(u'Enter a whole number.'),
  158
+        'max_value': _(u'Ensure this value is less than or equal to %s.'),
  159
+        'min_value': _(u'Ensure this value is greater than or equal to %s.'),
158 160
     }
159 161
 
160 162
     def __init__(self, max_value=None, min_value=None, *args, **kwargs):
@@ -181,9 +183,9 @@ def clean(self, value):
181 183
 
182 184
 class FloatField(Field):
183 185
     default_error_messages = {
184  
-        'invalid': ugettext_lazy(u'Enter a number.'),
185  
-        'max_value': ugettext_lazy(u'Ensure this value is less than or equal to %s.'),
186  
-        'min_value': ugettext_lazy(u'Ensure this value is greater than or equal to %s.'),
  186
+        'invalid': _(u'Enter a number.'),
  187
+        'max_value': _(u'Ensure this value is less than or equal to %s.'),
  188
+        'min_value': _(u'Ensure this value is greater than or equal to %s.'),
187 189
     }
188 190
 
189 191
     def __init__(self, max_value=None, min_value=None, *args, **kwargs):
@@ -210,12 +212,12 @@ def clean(self, value):
210 212
 
211 213
 class DecimalField(Field):
212 214
     default_error_messages = {
213  
-        'invalid': ugettext_lazy(u'Enter a number.'),
214  
-        'max_value': ugettext_lazy(u'Ensure this value is less than or equal to %s.'),
215  
-        'min_value': ugettext_lazy(u'Ensure this value is greater than or equal to %s.'),
216  
-        'max_digits': ugettext_lazy('Ensure that there are no more than %s digits in total.'),
217  
-        'max_decimal_places': ugettext_lazy('Ensure that there are no more than %s decimal places.'),
218  
-        'max_whole_digits': ugettext_lazy('Ensure that there are no more than %s digits before the decimal point.')
  215
+        'invalid': _(u'Enter a number.'),
  216
+        'max_value': _(u'Ensure this value is less than or equal to %s.'),
  217
+        'min_value': _(u'Ensure this value is greater than or equal to %s.'),
  218
+        'max_digits': _('Ensure that there are no more than %s digits in total.'),
  219
+        'max_decimal_places': _('Ensure that there are no more than %s decimal places.'),
  220
+        'max_whole_digits': _('Ensure that there are no more than %s digits before the decimal point.')
219 221
     }
220 222
 
221 223
     def __init__(self, max_value=None, min_value=None, max_digits=None, decimal_places=None, *args, **kwargs):
@@ -263,7 +265,7 @@ def clean(self, value):
263 265
 
264 266
 class DateField(Field):
265 267
     default_error_messages = {
266  
-        'invalid': ugettext_lazy(u'Enter a valid date.'),
  268
+        'invalid': _(u'Enter a valid date.'),
267 269
     }
268 270
 
269 271
     def __init__(self, input_formats=None, *args, **kwargs):
@@ -296,7 +298,7 @@ def clean(self, value):
296 298
 
297 299
 class TimeField(Field):
298 300
     default_error_messages = {
299  
-        'invalid': ugettext_lazy(u'Enter a valid time.')
  301
+        'invalid': _(u'Enter a valid time.')
300 302
     }
301 303
 
302 304
     def __init__(self, input_formats=None, *args, **kwargs):
@@ -335,7 +337,7 @@ def clean(self, value):
335 337
 class DateTimeField(Field):
336 338
     widget = DateTimeInput
337 339
     default_error_messages = {
338  
-        'invalid': ugettext_lazy(u'Enter a valid date/time.'),
  340
+        'invalid': _(u'Enter a valid date/time.'),
339 341
     }
340 342
 
341 343
     def __init__(self, input_formats=None, *args, **kwargs):
@@ -403,7 +405,7 @@ def clean(self, value):
403 405
 
404 406
 class EmailField(RegexField):
405 407
     default_error_messages = {
406  
-        'invalid': ugettext_lazy(u'Enter a valid e-mail address.'),
  408
+        'invalid': _(u'Enter a valid e-mail address.'),
407 409
     }
408 410
 
409 411
     def __init__(self, max_length=None, min_length=None, *args, **kwargs):
@@ -433,9 +435,9 @@ def __unicode__(self):
433 435
 class FileField(Field):
434 436
     widget = FileInput
435 437
     default_error_messages = {
436  
-        'invalid': ugettext_lazy(u"No file was submitted. Check the encoding type on the form."),
437  
-        'missing': ugettext_lazy(u"No file was submitted."),
438  
-        'empty': ugettext_lazy(u"The submitted file is empty."),
  438
+        'invalid': _(u"No file was submitted. Check the encoding type on the form."),
  439
+        'missing': _(u"No file was submitted."),
  440
+        'empty': _(u"The submitted file is empty."),
439 441
     }
440 442
 
441 443
     def __init__(self, *args, **kwargs):
@@ -457,7 +459,7 @@ def clean(self, data):
457 459
 
458 460
 class ImageField(FileField):
459 461
     default_error_messages = {
460  
-        'invalid_image': ugettext_lazy(u"Upload a valid image. The file you uploaded was either not an image or a corrupted image."),
  462
+        'invalid_image': _(u"Upload a valid image. The file you uploaded was either not an image or a corrupted image."),
461 463
     }
462 464
 
463 465
     def clean(self, data):
@@ -493,8 +495,8 @@ def clean(self, data):
493 495
 
494 496
 class URLField(RegexField):
495 497
     default_error_messages = {
496  
-        'invalid': ugettext_lazy(u'Enter a valid URL.'),
497  
-        'invalid_link': ugettext_lazy(u'This URL appears to be a broken link.'),
  498
+        'invalid': _(u'Enter a valid URL.'),
  499
+        'invalid_link': _(u'This URL appears to be a broken link.'),
498 500
     }
499 501
 
500 502
     def __init__(self, max_length=None, min_length=None, verify_exists=False,
@@ -555,7 +557,7 @@ def clean(self, value):
555 557
 class ChoiceField(Field):
556 558
     widget = Select
557 559
     default_error_messages = {
558  
-        'invalid_choice': ugettext_lazy(u'Select a valid choice. That choice is not one of the available choices.'),
  560
+        'invalid_choice': _(u'Select a valid choice. That choice is not one of the available choices.'),
559 561
     }
560 562
 
561 563
     def __init__(self, choices=(), required=True, widget=None, label=None,
@@ -594,8 +596,8 @@ class MultipleChoiceField(ChoiceField):
594 596
     hidden_widget = MultipleHiddenInput
595 597
     widget = SelectMultiple
596 598
     default_error_messages = {
597  
-        'invalid_choice': ugettext_lazy(u'Select a valid choice. %(value)s is not one of the available choices.'),
598  
-        'invalid_list': ugettext_lazy(u'Enter a list of values.'),
  599
+        'invalid_choice': _(u'Select a valid choice. %(value)s is not one of the available choices.'),
  600
+        'invalid_list': _(u'Enter a list of values.'),
599 601
     }
600 602
 
601 603
     def clean(self, value):
@@ -657,7 +659,7 @@ class MultiValueField(Field):
657 659
     You'll probably want to use this with MultiWidget.
658 660
     """
659 661
     default_error_messages = {
660  
-        'invalid': ugettext_lazy(u'Enter a list of values.'),
  662
+        'invalid': _(u'Enter a list of values.'),
661 663
     }
662 664
 
663 665
     def __init__(self, fields=(), *args, **kwargs):
@@ -719,8 +721,8 @@ def compress(self, data_list):
719 721
 
720 722
 class SplitDateTimeField(MultiValueField):
721 723
     default_error_messages = {
722  
-        'invalid_date': ugettext_lazy(u'Enter a valid date.'),
723  
-        'invalid_time': ugettext_lazy(u'Enter a valid time.'),
  724
+        'invalid_date': _(u'Enter a valid date.'),
  725
+        'invalid_time': _(u'Enter a valid time.'),
724 726
     }
725 727
 
726 728
     def __init__(self, *args, **kwargs):
@@ -748,7 +750,7 @@ def compress(self, data_list):
748 750
 
749 751
 class IPAddressField(RegexField):
750 752
     default_error_messages = {
751  
-        'invalid': ugettext_lazy(u'Enter a valid IPv4 address.'),
  753
+        'invalid': _(u'Enter a valid IPv4 address.'),
752 754
     }
753 755
 
754 756
     def __init__(self, *args, **kwargs):

0 notes on commit 2184248

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