[py3] Stopped attempting to translate bytes.

That goes actively against the goal of cleaning string handling.
This commit is contained in:
Aymeric Augustin 2012-08-18 11:30:48 +02:00
parent 2284419a2c
commit 85e7a5e140
3 changed files with 13 additions and 6 deletions

View File

@ -79,10 +79,10 @@ def pgettext(context, message):
def npgettext(context, singular, plural, number): def npgettext(context, singular, plural, number):
return _trans.npgettext(context, singular, plural, number) return _trans.npgettext(context, singular, plural, number)
ngettext_lazy = lazy(ngettext, bytes) gettext_lazy = lazy(gettext, str)
gettext_lazy = lazy(gettext, bytes) ngettext_lazy = lazy(ngettext, str)
ungettext_lazy = lazy(ungettext, six.text_type)
ugettext_lazy = lazy(ugettext, six.text_type) ugettext_lazy = lazy(ugettext, six.text_type)
ungettext_lazy = lazy(ungettext, six.text_type)
pgettext_lazy = lazy(pgettext, six.text_type) pgettext_lazy = lazy(pgettext, six.text_type)
npgettext_lazy = lazy(npgettext, six.text_type) npgettext_lazy = lazy(npgettext, six.text_type)

View File

@ -259,6 +259,11 @@ def do_translate(message, translation_function):
return result return result
def gettext(message): 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') return do_translate(message, 'gettext')
if six.PY3: if six.PY3:
@ -296,8 +301,10 @@ def do_ntranslate(singular, plural, number, translation_function):
def ngettext(singular, plural, number): def ngettext(singular, plural, number):
""" """
Returns a UTF-8 bytestring of the translation of either the singular or Returns a string of the translation of either the singular or plural,
plural, based on the number. 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') return do_ntranslate(singular, plural, number, 'ngettext')

View File

@ -232,7 +232,7 @@ class TranslationTests(TestCase):
""" """
Translating a string requiring no auto-escaping shouldn't change the "safe" status. 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)) self.assertEqual(SafeString, type(s))
with translation.override('de', deactivate=True): with translation.override('de', deactivate=True):
self.assertEqual(SafeUnicode, type(ugettext(s))) self.assertEqual(SafeUnicode, type(ugettext(s)))