summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-08-18 11:30:48 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-08-18 11:36:09 +0200
commit85e7a5e140104e7402ba51c313c9e53cb60d96f2 (patch)
tree4e6fc51997d3fd7bcb413c45bbb2645e0aa3bf06
parent2284419a2c7b5da643e53754e3bf82637b52017b (diff)
[py3] Stopped attempting to translate bytes.
That goes actively against the goal of cleaning string handling.
-rw-r--r--django/utils/translation/__init__.py6
-rw-r--r--django/utils/translation/trans_real.py11
-rw-r--r--tests/regressiontests/i18n/tests.py2
3 files changed, 13 insertions, 6 deletions
diff --git a/django/utils/translation/__init__.py b/django/utils/translation/__init__.py
index febde404a5..f3cc6348f6 100644
--- a/django/utils/translation/__init__.py
+++ b/django/utils/translation/__init__.py
@@ -79,10 +79,10 @@ def pgettext(context, message):
def npgettext(context, singular, plural, number):
return _trans.npgettext(context, singular, plural, number)
-ngettext_lazy = lazy(ngettext, bytes)
-gettext_lazy = lazy(gettext, bytes)
-ungettext_lazy = lazy(ungettext, six.text_type)
+gettext_lazy = lazy(gettext, str)
+ngettext_lazy = lazy(ngettext, str)
ugettext_lazy = lazy(ugettext, six.text_type)
+ungettext_lazy = lazy(ungettext, six.text_type)
pgettext_lazy = lazy(pgettext, six.text_type)
npgettext_lazy = lazy(npgettext, six.text_type)
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
index 9e6eadcd48..71282ff2b3 100644
--- a/django/utils/translation/trans_real.py
+++ b/django/utils/translation/trans_real.py
@@ -259,6 +259,11 @@ def do_translate(message, translation_function):
return result
def gettext(message):
+ """
+ Returns a string of the translation of the message.
+
+ Returns a string on Python 3 and an UTF-8-encoded bytestring on Python 2.
+ """
return do_translate(message, 'gettext')
if six.PY3:
@@ -296,8 +301,10 @@ def do_ntranslate(singular, plural, number, translation_function):
def ngettext(singular, plural, number):
"""
- Returns a UTF-8 bytestring of the translation of either the singular or
- plural, based on the number.
+ Returns a string of the translation of either the singular or plural,
+ based on the number.
+
+ Returns a string on Python 3 and an UTF-8-encoded bytestring on Python 2.
"""
return do_ntranslate(singular, plural, number, 'ngettext')
diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
index 9ca66bdb9b..1a8ff25ff3 100644
--- a/tests/regressiontests/i18n/tests.py
+++ b/tests/regressiontests/i18n/tests.py
@@ -232,7 +232,7 @@ class TranslationTests(TestCase):
"""
Translating a string requiring no auto-escaping shouldn't change the "safe" status.
"""
- s = mark_safe(b'Password')
+ s = mark_safe(str('Password'))
self.assertEqual(SafeString, type(s))
with translation.override('de', deactivate=True):
self.assertEqual(SafeUnicode, type(ugettext(s)))