diff options
| author | Claude Paroz <claude@2xlibre.net> | 2012-10-23 18:48:24 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2012-10-23 18:49:22 +0200 |
| commit | 9fd2f9c5f3c008f524874fd7cf78237e65bf567e (patch) | |
| tree | 048a0b9dcb02dad13751ab788c7c2b9d5491f8b0 /tests | |
| parent | 3541a10d492db6d1f509f3a50a024568c16c5229 (diff) | |
Fixed #19088 -- Always escape % inside blocktrans tag
Thanks vlinhart for the report and Ćukasz Rekucki for the patch.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/i18n/tests.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py index 1346383f3d..4054f85ef0 100644 --- a/tests/regressiontests/i18n/tests.py +++ b/tests/regressiontests/i18n/tests.py @@ -269,7 +269,6 @@ class TranslationTests(TestCase): (%(person)s is translated as %(personne)s in fr.po) Refs #16516. """ - from django.template import Template, Context with translation.override('fr'): t = Template('{% load i18n %}{% blocktrans %}My name is {{ person }}.{% endblocktrans %}') rendered = t.render(Context({'person': 'James'})) @@ -282,7 +281,6 @@ class TranslationTests(TestCase): (%(person) misses a 's' in fr.po, causing the string formatting to fail) Refs #18393. """ - from django.template import Template, Context with translation.override('fr'): t = Template('{% load i18n %}{% blocktrans %}My other name is {{ person }}.{% endblocktrans %}') rendered = t.render(Context({'person': 'James'})) @@ -821,6 +819,20 @@ class MiscTests(TestCase): self.assertEqual(t_plur.render(Context({'percent': 42, 'num': 1})), '42% stellt 1 Objekt dar') self.assertEqual(t_plur.render(Context({'percent': 42, 'num': 4})), '42% stellt 4 Objekte dar') + @override_settings(LOCALE_PATHS=extended_locale_paths) + def test_percent_formatting_in_blocktrans(self): + """ + Test that using Python's %-formatting is properly escaped in blocktrans, + singular or plural + """ + t_sing = Template("{% load i18n %}{% blocktrans %}There are %(num_comments)s comments{% endblocktrans %}") + t_plur = Template("{% load i18n %}{% blocktrans count num as number %}%(percent)s% represents {{ num }} object{% plural %}%(percent)s% represents {{ num }} objects{% endblocktrans %}") + with translation.override('de'): + # Strings won't get translated as they don't match after escaping % + self.assertEqual(t_sing.render(Context({'num_comments': 42})), 'There are %(num_comments)s comments') + self.assertEqual(t_plur.render(Context({'percent': 42, 'num': 1})), '%(percent)s% represents 1 object') + self.assertEqual(t_plur.render(Context({'percent': 42, 'num': 4})), '%(percent)s% represents 4 objects') + class ResolutionOrderI18NTests(TestCase): |
