diff options
| author | Claude Paroz <claude@2xlibre.net> | 2017-06-15 08:47:07 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2017-06-15 21:00:50 +0200 |
| commit | ceca221b31a38b01ee951fab82d5dc1c200c27b4 (patch) | |
| tree | 9d1b528d5982f41c5d1f92d42ef828dce63d2c4a | |
| parent | a6b5321ce997b899e540bb427cca98cb2b93a106 (diff) | |
Fixed #28304 -- Kept SafeData type for pgettext-translated strings
| -rw-r--r-- | django/utils/translation/trans_real.py | 2 | ||||
| -rw-r--r-- | tests/i18n/tests.py | 22 |
2 files changed, 15 insertions, 9 deletions
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py index b747f3aed1..6b3aeb127e 100644 --- a/django/utils/translation/trans_real.py +++ b/django/utils/translation/trans_real.py @@ -327,6 +327,8 @@ def pgettext(context, message): if CONTEXT_SEPARATOR in result: # Translation not found result = message + elif isinstance(message, SafeData): + result = mark_safe(result) return result diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index e9d8c35771..b5b30b8dc1 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -227,19 +227,23 @@ class TranslationTests(SimpleTestCase): s = mark_safe('') self.assertEqual(s, gettext(s)) + @override_settings(LOCALE_PATHS=extended_locale_paths) def test_safe_status(self): """ - Translating a string requiring no auto-escaping shouldn't change the - "safe" status. + Translating a string requiring no auto-escaping with gettext or pgettext + shouldn't change the "safe" status. """ - s = mark_safe('Password') - self.assertIs(type(s), SafeText) + trans_real._active = local() + trans_real._translations = {} + s1 = mark_safe('Password') + s2 = mark_safe('May') with translation.override('de', deactivate=True): - self.assertIs(type(gettext(s)), SafeText) - self.assertEqual('aPassword', SafeText('a') + s) - self.assertEqual('Passworda', s + SafeText('a')) - self.assertEqual('Passworda', s + mark_safe('a')) - self.assertEqual('aPassword', mark_safe('a') + s) + self.assertIs(type(gettext(s1)), SafeText) + self.assertIs(type(pgettext('month name', s2)), SafeText) + self.assertEqual('aPassword', SafeText('a') + s1) + self.assertEqual('Passworda', s1 + SafeText('a')) + self.assertEqual('Passworda', s1 + mark_safe('a')) + self.assertEqual('aPassword', mark_safe('a') + s1) self.assertEqual('as', mark_safe('a') + mark_safe('s')) def test_maclines(self): |
