Ticket #3063: ugettext.diff

File ugettext.diff, 1.7 KB (added by Antti Kaihola, 18 years ago)

[patch] Fixes translation of non-us-ascii message ids

  • usr/lib/python2.4/site-packages/django/utils/translation/trans_real.py

     
    244244    This function will be patched into the builtins module to provide the _
    245245    helper function. It will use the current thread as a discriminator to find
    246246    the translation object to use. If no current translation is activated, the
    247     message will be run through the default translation object.
     247    message will be run through the default translation object. Since the
     248    translation objects operate in unicode, conversion from and to the default
     249    encoding is done.
    248250    """
     251    from django.conf import settings
    249252    global _default, _active
    250253    t = _active.get(currentThread(), None)
     254    umessage = message.decode(settings.DEFAULT_CHARSET)
     255    # GNUTranslations.ugettext() is used instead of .gettext() since .gettext()
     256    # returns either an encoded string or a unicode string depending on whether
     257    # the msgid was found or not.  .ugettext() always expects a unicode msgid
     258    # and returns a unicode translation.
    251259    if t is not None:
    252         return t.gettext(message)
     260        return t.ugettext(umessage).encode(settings.DEFAULT_CHARSET)
    253261    if _default is None:
    254262        from django.conf import settings
    255263        _default = translation(settings.LANGUAGE_CODE)
    256     return _default.gettext(message)
     264    return _default.ugettext(umessage).encode(settings.DEFAULT_CHARSET)
    257265
    258266def gettext_noop(message):
    259267    """
Back to Top