Ticket #3704: patch.diff

File patch.diff, 6.1 KB (added by Baptiste <baptiste.goupil@…>, 18 years ago)
  • django/core/validators.py

     
    363363        self.lower, self.upper = lower, upper
    364364        if not error_message:
    365365            if lower and upper:
    366                 self.error_message = gettext("This value must be between %s and %s.") % (lower, upper)
     366                self.error_message = gettext("This value must be between %(lower)s and %(upper)s.") % {'lower': lower, 'upper': upper}
    367367            elif lower:
    368368                self.error_message = gettext("This value must be at least %s.") % lower
    369369            elif upper:
  • django/contrib/humanize/templatetags/humanize.py

     
     1from django.utils.translation import ngettext
    12from django import template
    23import re
    34
     
    34register = template.Library()
    45
    5 def ordinal(value):
     6def ordinal(value, sup=False):
    67    """
    78    Converts an integer to its ordinal as a string. 1 is '1st', 2 is '2nd',
     
    1213        value = int(value)
    1314    except ValueError:
    1415        return value
    15     t = ('th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th')
     16    t = (_('th'), _('st'), _('nd'), _('rd'), _('th'), _('th'), _('th'), _('th'), _('th'), _('th'))
     17    if sup:
     18        t = ['<sup>'+i+'</sup>' for i in t]
    1619    if value % 100 in (11, 12, 13): # special case
    17         return '%dth' % value
     20        return _('%(number)d%(string)') % {'number': value, 'string': t[0]}
    1821    return '%d%s' % (value, t[value % 10])
    1922register.filter(ordinal)
    2023
     
    4144    if value < 1000000:
    4245        return value
    4346    if value < 1000000000:
    44         return '%.1f million' % (value / 1000000.0)
     47        new_value = value / 1000000.0
     48        return ngettext('%(value).1f million', '%(value).1f million', new_value) % {'value': new_value}
    4549    if value < 1000000000000:
    46         return '%.1f billion' % (value / 1000000000.0)
     50        new_value = value / 1000000000.0
     51        return ngettext('%(value).1f billion', '%(value).1f billion', new_value) % {'value': new_value}
    4752    if value < 1000000000000000:
    48         return '%.1f trillion' % (value / 1000000000000.0)
     53        new_value = value / 1000000000000.0
     54        return ngettext('%(value).1f trillion', '%(value).1f trillion', new_value) % {'value': new_value}
    4955    return value
    5056register.filter(intword)
    5157
     
    6066        return value
    6167    if not 0 < value < 10:
    6268        return value
    63     return ('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine')[value-1]
     69    return (_('one'), _('two'), _('three'), _('four'), _('five'), _('six'), _('seven'), _('eight'), _('nine'))[value-1]
    6470register.filter(apnumber)
  • django/contrib/admin/views/doc.py

     
    168168            model = m
    169169            break
    170170    if model is None:
    171         raise Http404, _("Model %r not found in app %r") % (model_name, app_label)
     171        raise Http404, _("Model %(name)r not found in app %(label)r") % {'name': model_name, 'label': app_label}
    172172
    173173    opts = model._meta
    174174
     
    180180        if isinstance(field, models.ForeignKey):
    181181            data_type = related_object_name = field.rel.to.__name__
    182182            app_label = field.rel.to._meta.app_label
    183             verbose = utils.parse_rst((_("the related `%s.%s` object")  % (app_label, data_type)), 'model', _('model:') + data_type)
     183            verbose = utils.parse_rst((_("the related `%(label)s.%(type)s` object")  % {'label': app_label, 'type': data_type}), 'model', _('model:') + data_type)
    184184        else:
    185185            data_type = get_readable_field_data_type(field)
    186186            verbose = field.verbose_name
     
    211211
    212212    # Gather related objects
    213213    for rel in opts.get_all_related_objects():
    214         verbose = _("related `%s.%s` objects") % (rel.opts.app_label, rel.opts.object_name)
     214        verbose = _("related `%(label)s.%(name)s` objects") % {'label': rel.opts.app_label, 'name': rel.opts.object_name}
    215215        accessor = rel.get_accessor_name()
    216216        fields.append({
    217217            'name'      : "%s.all" % accessor,
  • django/bin/make-messages.py

     
    8181                    src = pythonize_re.sub('\n#', src)
    8282                    open(os.path.join(dirpath, '%s.py' % file), "wb").write(src)
    8383                    thefile = '%s.py' % file
    84                     cmd = 'xgettext %s -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy -o - "%s"' % (
     84                    cmd = 'xgettext %s -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy --from-code UTF-8 -o - "%s"' % (
    8585                        os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile))
    8686                    (stdin, stdout, stderr) = os.popen3(cmd, 'b')
    8787                    msgs = stdout.read()
     
    103103                        open(os.path.join(dirpath, '%s.py' % file), "wb").write(templatize(src))
    104104                        thefile = '%s.py' % file
    105105                    if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
    106                     cmd = 'xgettext %s -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy -o - "%s"' % (
     106                    cmd = 'xgettext %s -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy --from-code UTF-8 -o - "%s"' % (
    107107                        os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile))
    108108                    (stdin, stdout, stderr) = os.popen3(cmd, 'b')
    109109                    msgs = stdout.read()
Back to Top