Ticket #5056: ugettext.5.diff

File ugettext.5.diff, 5.5 KB (added by Christopher Lenz <cmlenz@…>, 8 years ago)

Fix typo in previous patch

  • django/utils/translation/trans_real.py

     
    247247        _default = translation(settings.LANGUAGE_CODE)
    248248    return _default
    249249
    250 def do_translate(message, translation_function):
     250def gettext(message):
    251251    """
    252     Translate 'message' using the given 'translation_function' name -- which
    253     will be either gettext or ugettext.
     252    This function will be patched into the builtins module to provide the _
     253    helper function. It will use the current thread as a discriminator to find
     254    the translation object to use. If no current translation is activated, the
     255    message will be run through the default translation object.
    254256    """
    255257    global _default, _active
    256258    t = _active.get(currentThread(), None)
    257259    if t is not None:
    258         return getattr(t, translation_function)(message)
     260        return t.ugettext(message)
    259261    if _default is None:
    260262        from django.conf import settings
    261263        _default = translation(settings.LANGUAGE_CODE)
    262     return getattr(_default, translation_function)(message)
     264    return _default.ugettext(message)
     265ugettext = gettext
    263266
    264 def gettext(message):
    265     """
    266     This function will be patched into the builtins module to provide the _
    267     helper function. It will use the current thread as a discriminator to find
    268     the translation object to use. If no current translation is activated, the
    269     message will be run through the default translation object.
    270     """
    271     return do_translate(message, 'gettext')
    272 
    273 def ugettext(message):
    274     return do_translate(message, 'ugettext')
    275 
    276267def gettext_noop(message):
    277268    """
    278269    Marks strings for translation but doesn't translate them now. This can be
     
    282273    """
    283274    return message
    284275
    285 def do_ntranslate(singular, plural, number, translation_function):
     276def ngettext(singular, plural, number):
     277    """
     278    Returns a unicode string of the translation of either the singular or
     279    plural, based on the number.
     280    """
    286281    global _default, _active
    287 
    288282    t = _active.get(currentThread(), None)
    289283    if t is not None:
    290         return getattr(t, translation_function)(singular, plural, number)
     284        return t.ungettext(singular, plural, number)
    291285    if _default is None:
    292286        from django.conf import settings
    293287        _default = translation(settings.LANGUAGE_CODE)
    294     return getattr(_default, translation_function)(singular, plural, number)
     288    return _default.ungettext(singular, plural, number)
     289ungettext = ngettext
    295290
    296 def ngettext(singular, plural, number):
    297     """
    298     Returns a UTF-8 bytestring of the translation of either the singular or
    299     plural, based on the number.
    300     """
    301     return do_ntranslate(singular, plural, number, 'ngettext')
    302 
    303 def ungettext(singular, plural, number):
    304     """
    305     Returns a unicode strings of the translation of either the singular or
    306     plural, based on the number.
    307     """
    308     return do_ntranslate(singular, plural, number, 'ungettext')
    309 
    310291def check_for_language(lang_code):
    311292    """
    312293    Checks whether there is a global language file for the given language
  • django/utils/translation/__init__.py

     
    4848
    4949def gettext_noop(message):
    5050    return real_gettext_noop(message)
    51 
    5251ugettext_noop = gettext_noop
    5352
    5453def gettext(message):
    5554    return real_gettext(message)
     55ugettext = gettext
    5656
    5757def ngettext(singular, plural, number):
    5858    return real_ngettext(singular, plural, number)
     59ungettext = ngettext
    5960
    60 def ugettext(message):
    61     return real_ugettext(message)
    62 
    63 def ungettext(singular, plural, number):
    64     return real_ungettext(singular, plural, number)
    65 
    6661def string_concat(*strings):
    6762    return real_string_concat(*strings)
    6863
    69 ngettext_lazy = lazy(ngettext, str)
    70 gettext_lazy = lazy(gettext, str)
    71 ungettext_lazy = lazy(ungettext, unicode)
    72 ugettext_lazy = lazy(ugettext, unicode)
     64ngettext_lazy = lazy(ngettext, unicode)
     65gettext_lazy = lazy(gettext, unicode)
     66ungettext_lazy = ngettext_lazy
     67ugettext_lazy = gettext_lazy
    7368string_concat = lazy(string_concat, unicode)
    7469
    7570def activate(language):
  • django/utils/translation/trans_null.py

     
    66from django.utils.encoding import force_unicode
    77
    88def ngettext(singular, plural, number):
    9     if number == 1: return singular
    10     return plural
    11 ngettext_lazy = ngettext
     9    return force_unicode({1: singular}.get(number, plural))
     10ungettext = ngettext_lazy = ngettext
    1211
    13 def ungettext(singular, plural, number):
    14     return force_unicode(ngettext(singular, plural, number))
    15 
    1612string_concat = lambda *strings: u''.join([force_unicode(el) for el in strings])
    1713activate = lambda x: None
    1814deactivate = deactivate_all = install = lambda: None
     
    3228}
    3329
    3430def gettext(message):
    35     return TECHNICAL_ID_MAP.get(message, message)
     31    return force_unicode(TECHNICAL_ID_MAP.get(message, message))
     32ugettext = gettext_noop = gettext_lazy = _ = gettext
    3633
    37 def ugettext(message):
    38     return force_unicode(gettext(message))
    39 
    40 gettext_noop = gettext_lazy = _ = gettext
    41 
    4234def to_locale(language):
    4335    p = language.find('-')
    4436    if p >= 0:
Back to Top