Ticket #18760: aliased_ugettext.diff

File aliased_ugettext.diff, 5.1 KB (added by Claude Paroz, 12 years ago)

Remove the utf-8-encoded version of gettext

  • django/utils/translation/__init__.py

    diff --git a/django/utils/translation/__init__.py b/django/utils/translation/__init__.py
    index febde40..673a783 100644
    a b ugettext_noop = gettext_noop  
    6464def gettext(message):
    6565    return _trans.gettext(message)
    6666
     67ugettext = gettext
     68
    6769def ngettext(singular, plural, number):
    6870    return _trans.ngettext(singular, plural, number)
    6971
    70 def ugettext(message):
    71     return _trans.ugettext(message)
    72 
    73 def ungettext(singular, plural, number):
    74     return _trans.ungettext(singular, plural, number)
     72ungettext = ngettext
    7573
    7674def pgettext(context, message):
    7775    return _trans.pgettext(context, message)
    def pgettext(context, message):  
    7977def npgettext(context, singular, plural, number):
    8078    return _trans.npgettext(context, singular, plural, number)
    8179
    82 ngettext_lazy = lazy(ngettext, bytes)
    83 gettext_lazy = lazy(gettext, bytes)
    84 ungettext_lazy = lazy(ungettext, six.text_type)
    85 ugettext_lazy = lazy(ugettext, six.text_type)
     80ungettext_lazy = ngettext_lazy = lazy(ngettext, six.text_type)
     81ugettext_lazy = gettext_lazy = lazy(gettext, six.text_type)
    8682pgettext_lazy = lazy(pgettext, six.text_type)
    8783npgettext_lazy = lazy(npgettext, six.text_type)
    8884
  • django/utils/translation/trans_null.py

    diff --git a/django/utils/translation/trans_null.py b/django/utils/translation/trans_null.py
    index 5c51468..92d1205 100644
    a b from django.utils.encoding import force_text  
    77from django.utils.safestring import mark_safe, SafeData
    88
    99def ngettext(singular, plural, number):
    10     if number == 1: return singular
    11     return plural
    12 ngettext_lazy = ngettext
    13 
    14 def ungettext(singular, plural, number):
    15     return force_text(ngettext(singular, plural, number))
     10    if number == 1: return force_text(singular)
     11    return force_text(plural)
     12ngettext_lazy = ungettext = ngettext
    1613
    1714def pgettext(context, message):
    18     return ugettext(message)
     15    return gettext(message)
    1916
    2017def npgettext(context, singular, plural, number):
    21     return ungettext(singular, plural, number)
     18    return ngettext(singular, plural, number)
    2219
    2320activate = lambda x: None
    2421deactivate = deactivate_all = lambda: None
    TECHNICAL_ID_MAP = {  
    3835}
    3936
    4037def gettext(message):
    41     result = TECHNICAL_ID_MAP.get(message, message)
     38    result = TECHNICAL_ID_MAP.get(message, force_text(message))
    4239    if isinstance(message, SafeData):
    4340        return mark_safe(result)
    4441    return result
    4542
    46 def ugettext(message):
    47     return force_text(gettext(message))
    48 
    49 gettext_noop = gettext_lazy = _ = gettext
     43gettext_noop = gettext_lazy = ugettext = _ = gettext
    5044
    5145def to_locale(language):
    5246    p = language.find('-')
  • django/utils/translation/trans_real.py

    diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
    index 9e6eadc..afb3160 100644
    a b def do_translate(message, translation_function):  
    259259    return result
    260260
    261261def gettext(message):
    262     return do_translate(message, 'gettext')
    263 
    264 if six.PY3:
    265     ugettext = gettext
    266 else:
    267     def ugettext(message):
     262    if six.PY3:
     263        return do_translate(message, 'gettext')
     264    else:
    268265        return do_translate(message, 'ugettext')
    269266
     267ugettext = gettext
     268
    270269def pgettext(context, message):
    271270    result = ugettext("%s%s%s" % (context, CONTEXT_SEPARATOR, message))
    272271    if CONTEXT_SEPARATOR in result:
    def do_ntranslate(singular, plural, number, translation_function):  
    296295
    297296def ngettext(singular, plural, number):
    298297    """
    299     Returns a UTF-8 bytestring of the translation of either the singular or
     298    Returns a unicode string of the translation of either the singular or
    300299    plural, based on the number.
    301300    """
    302     return do_ntranslate(singular, plural, number, 'ngettext')
    303 
    304 if six.PY3:
    305     ungettext = ngettext
    306 else:
    307     def ungettext(singular, plural, number):
    308         """
    309         Returns a unicode strings of the translation of either the singular or
    310         plural, based on the number.
    311         """
     301    if six.PY3:
     302        return do_ntranslate(singular, plural, number, 'ngettext')
     303    else:
    312304        return do_ntranslate(singular, plural, number, 'ungettext')
    313305
     306ungettext = ngettext
     307
    314308def npgettext(context, singular, plural, number):
    315309    result = ungettext("%s%s%s" % (context, CONTEXT_SEPARATOR, singular),
    316310                       "%s%s%s" % (context, CONTEXT_SEPARATOR, plural),
  • docs/ref/utils.txt

    diff --git a/docs/ref/utils.txt b/docs/ref/utils.txt
    index 97643c2..6c3e99d 100644
    a b For a complete discussion on the usage of the following see the  
    595595:doc:`translation documentation </topics/i18n/translation>`.
    596596
    597597.. function:: gettext(message)
    598 
    599     Translates ``message`` and returns it in a UTF-8 bytestring
    600 
    601598.. function:: ugettext(message)
    602599
    603600    Translates ``message`` and returns it in a unicode string
    604601
     602    .. versionchanged:: 1.5
     603
     604    ``gettext`` used to return an UTF8-encoded string. Both ``gettext`` and
     605    ``ugettext`` return now Unicode.
     606
    605607.. function:: pgettext(context, message)
    606608
    607609    Translates ``message`` given the ``context`` and returns
Back to Top