Django

Code

Changeset 6642

Show
Ignore:
Timestamp:
11/03/07 21:08:02 (1 year ago)
Author:
mtredinnick
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/newforms/fields.py

    r6625 r6642  
    1717    from sets import Set as set 
    1818 
    19 from django.utils.translation import ugettext_lazy 
     19from django.utils.translation import ugettext_lazy as _ 
    2020from django.utils.encoding import StrAndUnicode, smart_unicode 
    2121 
     
    4343    hidden_widget = HiddenInput # Default widget to use when rendering this as "hidden". 
    4444    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.'), 
    4747    } 
    4848 
     
    8888    def _build_error_messages(self, extra_error_messages): 
    8989        error_messages = {} 
     90 
    9091        def get_default_error_messages(klass): 
    9192            for base_class in klass.__bases__: 
     
    9394            if hasattr(klass, 'default_error_messages'): 
    9495                error_messages.update(klass.default_error_messages) 
     96 
    9597        get_default_error_messages(self.__class__) 
    9698        if extra_error_messages: 
     
    125127class CharField(Field): 
    126128    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).'), 
    129131    } 
    130132 
     
    153155class IntegerField(Field): 
    154156    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.'), 
    158160    } 
    159161 
     
    182184class FloatField(Field): 
    183185    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.'), 
    187189    } 
    188190 
     
    211213class DecimalField(Field): 
    212214    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.') 
    219221    } 
    220222 
     
    264266class DateField(Field): 
    265267    default_error_messages = { 
    266         'invalid': ugettext_lazy(u'Enter a valid date.'), 
     268        'invalid': _(u'Enter a valid date.'), 
    267269    } 
    268270 
     
    297299class TimeField(Field): 
    298300    default_error_messages = { 
    299         'invalid': ugettext_lazy(u'Enter a valid time.') 
     301        'invalid': _(u'Enter a valid time.') 
    300302    } 
    301303 
     
    336338    widget = DateTimeInput 
    337339    default_error_messages = { 
    338         'invalid': ugettext_lazy(u'Enter a valid date/time.'), 
     340        'invalid': _(u'Enter a valid date/time.'), 
    339341    } 
    340342 
     
    404406class EmailField(RegexField): 
    405407    default_error_messages = { 
    406         'invalid': ugettext_lazy(u'Enter a valid e-mail address.'), 
     408        'invalid': _(u'Enter a valid e-mail address.'), 
    407409    } 
    408410 
     
    434436    widget = FileInput 
    435437    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."), 
    439441    } 
    440442 
     
    458460class ImageField(FileField): 
    459461    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."), 
    461463    } 
    462464 
     
    494496class URLField(RegexField): 
    495497    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.'), 
    498500    } 
    499501 
     
    556558    widget = Select 
    557559    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.'), 
    559561    } 
    560562 
     
    595597    widget = SelectMultiple 
    596598    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.'), 
    599601    } 
    600602 
     
    658660    """ 
    659661    default_error_messages = { 
    660         'invalid': ugettext_lazy(u'Enter a list of values.'), 
     662        'invalid': _(u'Enter a list of values.'), 
    661663    } 
    662664 
     
    720722class SplitDateTimeField(MultiValueField): 
    721723    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.'), 
    724726    } 
    725727 
     
    749751class IPAddressField(RegexField): 
    750752    default_error_messages = { 
    751         'invalid': ugettext_lazy(u'Enter a valid IPv4 address.'), 
     753        'invalid': _(u'Enter a valid IPv4 address.'), 
    752754    } 
    753755