Fixed #28304 -- Kept SafeData type for pgettext-translated strings
This commit is contained in:
parent
a6b5321ce9
commit
ceca221b31
|
@ -327,6 +327,8 @@ def pgettext(context, message):
|
||||||
if CONTEXT_SEPARATOR in result:
|
if CONTEXT_SEPARATOR in result:
|
||||||
# Translation not found
|
# Translation not found
|
||||||
result = message
|
result = message
|
||||||
|
elif isinstance(message, SafeData):
|
||||||
|
result = mark_safe(result)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -227,19 +227,23 @@ class TranslationTests(SimpleTestCase):
|
||||||
s = mark_safe('')
|
s = mark_safe('')
|
||||||
self.assertEqual(s, gettext(s))
|
self.assertEqual(s, gettext(s))
|
||||||
|
|
||||||
|
@override_settings(LOCALE_PATHS=extended_locale_paths)
|
||||||
def test_safe_status(self):
|
def test_safe_status(self):
|
||||||
"""
|
"""
|
||||||
Translating a string requiring no auto-escaping shouldn't change the
|
Translating a string requiring no auto-escaping with gettext or pgettext
|
||||||
"safe" status.
|
shouldn't change the "safe" status.
|
||||||
"""
|
"""
|
||||||
s = mark_safe('Password')
|
trans_real._active = local()
|
||||||
self.assertIs(type(s), SafeText)
|
trans_real._translations = {}
|
||||||
|
s1 = mark_safe('Password')
|
||||||
|
s2 = mark_safe('May')
|
||||||
with translation.override('de', deactivate=True):
|
with translation.override('de', deactivate=True):
|
||||||
self.assertIs(type(gettext(s)), SafeText)
|
self.assertIs(type(gettext(s1)), SafeText)
|
||||||
self.assertEqual('aPassword', SafeText('a') + s)
|
self.assertIs(type(pgettext('month name', s2)), SafeText)
|
||||||
self.assertEqual('Passworda', s + SafeText('a'))
|
self.assertEqual('aPassword', SafeText('a') + s1)
|
||||||
self.assertEqual('Passworda', s + mark_safe('a'))
|
self.assertEqual('Passworda', s1 + SafeText('a'))
|
||||||
self.assertEqual('aPassword', mark_safe('a') + s)
|
self.assertEqual('Passworda', s1 + mark_safe('a'))
|
||||||
|
self.assertEqual('aPassword', mark_safe('a') + s1)
|
||||||
self.assertEqual('as', mark_safe('a') + mark_safe('s'))
|
self.assertEqual('as', mark_safe('a') + mark_safe('s'))
|
||||||
|
|
||||||
def test_maclines(self):
|
def test_maclines(self):
|
||||||
|
|
Loading…
Reference in New Issue