Browse files

Fixed #19272 -- Fixed gettext_lazy returned type on Python 2

Thanks tyrion for the report.
  • Loading branch information...
1 parent 1620c27 commit 550ddc66b496473c8ee282c7ab6be5885a359d75 @claudep claudep committed Nov 14, 2012
Showing with 6 additions and 1 deletion.
  1. +2 −1 django/utils/translation/trans_real.py
  2. +4 −0 tests/regressiontests/i18n/tests.py
View
3 django/utils/translation/trans_real.py
@@ -246,7 +246,8 @@ def do_translate(message, translation_function):
"""
global _default
- eol_message = message.replace('\r\n', '\n').replace('\r', '\n')
+ # str() is allowing a bytestring message to remain bytestring on Python 2
+ eol_message = message.replace(str('\r\n'), str('\n')).replace(str('\r'), str('\n'))
t = getattr(_active, "value", None)
if t is not None:
result = getattr(t, translation_function)(eol_message)
View
4 tests/regressiontests/i18n/tests.py
@@ -83,6 +83,10 @@ def test_lazy_objects(self):
s4 = ugettext_lazy('Some other string')
self.assertEqual(False, s == s4)
+ if not six.PY3:
+ # On Python 2, gettext_lazy should not transform a bytestring to unicode
+ self.assertEqual(gettext_lazy(b"test").upper(), b"TEST")
+
def test_lazy_pickle(self):
s1 = ugettext_lazy("test")
self.assertEqual(six.text_type(s1), "test")

0 comments on commit 550ddc6

Please sign in to comment.