Ticket #19272: 19272-1.diff

File 19272-1.diff, 1.3 KB (added by Claude Paroz, 12 years ago)

Preserve bytestrings in gettext[_lazy] calls

  • django/utils/translation/trans_real.py

    diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
    index 9e94840..1bcef2d 100644
    a b def do_translate(message, translation_function):  
    246246    """
    247247    global _default
    248248
    249     eol_message = message.replace('\r\n', '\n').replace('\r', '\n')
     249    # str() is allowing a bytestring message to remain bytestring on Python 2
     250    eol_message = message.replace(str('\r\n'), str('\n')).replace(str('\r'), str('\n'))
    250251    t = getattr(_active, "value", None)
    251252    if t is not None:
    252253        result = getattr(t, translation_function)(eol_message)
  • tests/regressiontests/i18n/tests.py

    diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
    index 4054f85..2e0c097 100644
    a b class TranslationTests(TestCase):  
    8383        s4 = ugettext_lazy('Some other string')
    8484        self.assertEqual(False, s == s4)
    8585
     86        if not six.PY3:
     87            # On Python 2, gettext_lazy should not transform a bytestring to unicode
     88            self.assertEqual(gettext_lazy(b"test").upper(), b"TEST")
     89
    8690    def test_lazy_pickle(self):
    8791        s1 = ugettext_lazy("test")
    8892        self.assertEqual(six.text_type(s1), "test")
Back to Top