diff options
Diffstat (limited to 'tests/template_tests/syntax_tests/i18n/test_blocktranslate.py')
| -rw-r--r-- | tests/template_tests/syntax_tests/i18n/test_blocktranslate.py | 247 |
1 files changed, 131 insertions, 116 deletions
diff --git a/tests/template_tests/syntax_tests/i18n/test_blocktranslate.py b/tests/template_tests/syntax_tests/i18n/test_blocktranslate.py index 11bd456ea8..8edacd87e2 100644 --- a/tests/template_tests/syntax_tests/i18n/test_blocktranslate.py +++ b/tests/template_tests/syntax_tests/i18n/test_blocktranslate.py @@ -15,12 +15,12 @@ from .base import MultipleLocaleActivationTestCase, extended_locale_paths, here def setup(templates, *args, **kwargs): - blocktrans_setup = base_setup(templates, *args, **kwargs) - blocktranslate_setup = base_setup({ + blocktranslate_setup = base_setup(templates, *args, **kwargs) + blocktrans_setup = base_setup({ name: template.replace( - '{% blocktrans ', '{% blocktranslate ' + '{% blocktranslate ', '{% blocktrans ' ).replace( - '{% endblocktrans %}', '{% endblocktranslate %}' + '{% endblocktranslate %}', '{% endblocktrans %}' ) for name, template in templates.items() }) @@ -46,65 +46,65 @@ def setup(templates, *args, **kwargs): class I18nBlockTransTagTests(SimpleTestCase): libraries = {'i18n': 'django.templatetags.i18n'} - @setup({'i18n03': '{% load i18n %}{% blocktrans %}{{ anton }}{% endblocktrans %}'}) + @setup({'i18n03': '{% load i18n %}{% blocktranslate %}{{ anton }}{% endblocktranslate %}'}) def test_i18n03(self): """simple translation of a variable""" output = self.engine.render_to_string('i18n03', {'anton': 'Å'}) self.assertEqual(output, 'Å') - @setup({'i18n04': '{% load i18n %}{% blocktrans with berta=anton|lower %}{{ berta }}{% endblocktrans %}'}) + @setup({'i18n04': '{% load i18n %}{% blocktranslate with berta=anton|lower %}{{ berta }}{% endblocktranslate %}'}) def test_i18n04(self): """simple translation of a variable and filter""" output = self.engine.render_to_string('i18n04', {'anton': 'Å'}) self.assertEqual(output, 'å') @setup({'legacyi18n04': '{% load i18n %}' - '{% blocktrans with anton|lower as berta %}{{ berta }}{% endblocktrans %}'}) + '{% blocktranslate with anton|lower as berta %}{{ berta }}{% endblocktranslate %}'}) def test_legacyi18n04(self): """simple translation of a variable and filter""" output = self.engine.render_to_string('legacyi18n04', {'anton': 'Å'}) self.assertEqual(output, 'å') - @setup({'i18n05': '{% load i18n %}{% blocktrans %}xxx{{ anton }}xxx{% endblocktrans %}'}) + @setup({'i18n05': '{% load i18n %}{% blocktranslate %}xxx{{ anton }}xxx{% endblocktranslate %}'}) def test_i18n05(self): """simple translation of a string with interpolation""" output = self.engine.render_to_string('i18n05', {'anton': 'yyy'}) self.assertEqual(output, 'xxxyyyxxx') @setup({'i18n07': '{% load i18n %}' - '{% blocktrans count counter=number %}singular{% plural %}' - '{{ counter }} plural{% endblocktrans %}'}) + '{% blocktranslate count counter=number %}singular{% plural %}' + '{{ counter }} plural{% endblocktranslate %}'}) def test_i18n07(self): """translation of singular form""" output = self.engine.render_to_string('i18n07', {'number': 1}) self.assertEqual(output, 'singular') @setup({'legacyi18n07': '{% load i18n %}' - '{% blocktrans count number as counter %}singular{% plural %}' - '{{ counter }} plural{% endblocktrans %}'}) + '{% blocktranslate count number as counter %}singular{% plural %}' + '{{ counter }} plural{% endblocktranslate %}'}) def test_legacyi18n07(self): """translation of singular form""" output = self.engine.render_to_string('legacyi18n07', {'number': 1}) self.assertEqual(output, 'singular') @setup({'i18n08': '{% load i18n %}' - '{% blocktrans count number as counter %}singular{% plural %}' - '{{ counter }} plural{% endblocktrans %}'}) + '{% blocktranslate count number as counter %}singular{% plural %}' + '{{ counter }} plural{% endblocktranslate %}'}) def test_i18n08(self): """translation of plural form""" output = self.engine.render_to_string('i18n08', {'number': 2}) self.assertEqual(output, '2 plural') @setup({'legacyi18n08': '{% load i18n %}' - '{% blocktrans count counter=number %}singular{% plural %}' - '{{ counter }} plural{% endblocktrans %}'}) + '{% blocktranslate count counter=number %}singular{% plural %}' + '{{ counter }} plural{% endblocktranslate %}'}) def test_legacyi18n08(self): """translation of plural form""" output = self.engine.render_to_string('legacyi18n08', {'number': 2}) self.assertEqual(output, '2 plural') @setup({'i18n17': '{% load i18n %}' - '{% blocktrans with berta=anton|escape %}{{ berta }}{% endblocktrans %}'}) + '{% blocktranslate with berta=anton|escape %}{{ berta }}{% endblocktranslate %}'}) def test_i18n17(self): """ Escaping inside blocktranslate and translate works as if it was @@ -114,37 +114,37 @@ class I18nBlockTransTagTests(SimpleTestCase): self.assertEqual(output, 'α & β') @setup({'i18n18': '{% load i18n %}' - '{% blocktrans with berta=anton|force_escape %}{{ berta }}{% endblocktrans %}'}) + '{% blocktranslate with berta=anton|force_escape %}{{ berta }}{% endblocktranslate %}'}) def test_i18n18(self): output = self.engine.render_to_string('i18n18', {'anton': 'α & β'}) self.assertEqual(output, 'α & β') - @setup({'i18n19': '{% load i18n %}{% blocktrans %}{{ andrew }}{% endblocktrans %}'}) + @setup({'i18n19': '{% load i18n %}{% blocktranslate %}{{ andrew }}{% endblocktranslate %}'}) def test_i18n19(self): output = self.engine.render_to_string('i18n19', {'andrew': 'a & b'}) self.assertEqual(output, 'a & b') - @setup({'i18n21': '{% load i18n %}{% blocktrans %}{{ andrew }}{% endblocktrans %}'}) + @setup({'i18n21': '{% load i18n %}{% blocktranslate %}{{ andrew }}{% endblocktranslate %}'}) def test_i18n21(self): output = self.engine.render_to_string('i18n21', {'andrew': mark_safe('a & b')}) self.assertEqual(output, 'a & b') @setup({'legacyi18n17': '{% load i18n %}' - '{% blocktrans with anton|escape as berta %}{{ berta }}{% endblocktrans %}'}) + '{% blocktranslate with anton|escape as berta %}{{ berta }}{% endblocktranslate %}'}) def test_legacyi18n17(self): output = self.engine.render_to_string('legacyi18n17', {'anton': 'α & β'}) self.assertEqual(output, 'α & β') @setup({'legacyi18n18': '{% load i18n %}' - '{% blocktrans with anton|force_escape as berta %}' - '{{ berta }}{% endblocktrans %}'}) + '{% blocktranslate with anton|force_escape as berta %}' + '{{ berta }}{% endblocktranslate %}'}) def test_legacyi18n18(self): output = self.engine.render_to_string('legacyi18n18', {'anton': 'α & β'}) self.assertEqual(output, 'α & β') @setup({'i18n26': '{% load i18n %}' - '{% blocktrans with extra_field=myextra_field count counter=number %}' - 'singular {{ extra_field }}{% plural %}plural{% endblocktrans %}'}) + '{% blocktranslate with extra_field=myextra_field count counter=number %}' + 'singular {{ extra_field }}{% plural %}plural{% endblocktranslate %}'}) def test_i18n26(self): """ translation of plural form with extra field in singular form (#13568) @@ -153,15 +153,15 @@ class I18nBlockTransTagTests(SimpleTestCase): self.assertEqual(output, 'singular test') @setup({'legacyi18n26': '{% load i18n %}' - '{% blocktrans with myextra_field as extra_field count number as counter %}' - 'singular {{ extra_field }}{% plural %}plural{% endblocktrans %}'}) + '{% blocktranslate with myextra_field as extra_field count number as counter %}' + 'singular {{ extra_field }}{% plural %}plural{% endblocktranslate %}'}) def test_legacyi18n26(self): output = self.engine.render_to_string('legacyi18n26', {'myextra_field': 'test', 'number': 1}) self.assertEqual(output, 'singular test') - @setup({'i18n27': '{% load i18n %}{% blocktrans count counter=number %}' + @setup({'i18n27': '{% load i18n %}{% blocktranslate count counter=number %}' '{{ counter }} result{% plural %}{{ counter }} results' - '{% endblocktrans %}'}) + '{% endblocktranslate %}'}) def test_i18n27(self): """translation of singular form in Russian (#14126)""" with translation.override('ru'): @@ -169,30 +169,30 @@ class I18nBlockTransTagTests(SimpleTestCase): self.assertEqual(output, '1 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442') @setup({'legacyi18n27': '{% load i18n %}' - '{% blocktrans count number as counter %}{{ counter }} result' - '{% plural %}{{ counter }} results{% endblocktrans %}'}) + '{% blocktranslate count number as counter %}{{ counter }} result' + '{% plural %}{{ counter }} results{% endblocktranslate %}'}) def test_legacyi18n27(self): with translation.override('ru'): output = self.engine.render_to_string('legacyi18n27', {'number': 1}) self.assertEqual(output, '1 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442') @setup({'i18n28': '{% load i18n %}' - '{% blocktrans with a=anton b=berta %}{{ a }} + {{ b }}{% endblocktrans %}'}) + '{% blocktranslate with a=anton b=berta %}{{ a }} + {{ b }}{% endblocktranslate %}'}) def test_i18n28(self): """simple translation of multiple variables""" output = self.engine.render_to_string('i18n28', {'anton': 'α', 'berta': 'β'}) self.assertEqual(output, 'α + β') @setup({'legacyi18n28': '{% load i18n %}' - '{% blocktrans with anton as a and berta as b %}' - '{{ a }} + {{ b }}{% endblocktrans %}'}) + '{% blocktranslate with anton as a and berta as b %}' + '{{ a }} + {{ b }}{% endblocktranslate %}'}) def test_legacyi18n28(self): output = self.engine.render_to_string('legacyi18n28', {'anton': 'α', 'berta': 'β'}) self.assertEqual(output, 'α + β') - # blocktrans handling of variables which are not in the context. - # this should work as if blocktrans was not there (#19915) - @setup({'i18n34': '{% load i18n %}{% blocktrans %}{{ missing }}{% endblocktrans %}'}) + # blocktranslate handling of variables which are not in the context. + # this should work as if blocktranslate was not there (#19915) + @setup({'i18n34': '{% load i18n %}{% blocktranslate %}{{ missing }}{% endblocktranslate %}'}) def test_i18n34(self): output = self.engine.render_to_string('i18n34') if self.engine.string_if_invalid: @@ -200,7 +200,7 @@ class I18nBlockTransTagTests(SimpleTestCase): else: self.assertEqual(output, '') - @setup({'i18n34_2': '{% load i18n %}{% blocktrans with a=\'α\' %}{{ missing }}{% endblocktrans %}'}) + @setup({'i18n34_2': '{% load i18n %}{% blocktranslate with a=\'α\' %}{{ missing }}{% endblocktranslate %}'}) def test_i18n34_2(self): output = self.engine.render_to_string('i18n34_2') if self.engine.string_if_invalid: @@ -208,7 +208,7 @@ class I18nBlockTransTagTests(SimpleTestCase): else: self.assertEqual(output, '') - @setup({'i18n34_3': '{% load i18n %}{% blocktrans with a=anton %}{{ missing }}{% endblocktrans %}'}) + @setup({'i18n34_3': '{% load i18n %}{% blocktranslate with a=anton %}{{ missing }}{% endblocktranslate %}'}) def test_i18n34_3(self): output = self.engine.render_to_string( 'i18n34_3', {'anton': '\xce\xb1'}) @@ -218,16 +218,16 @@ class I18nBlockTransTagTests(SimpleTestCase): self.assertEqual(output, '') @setup({'i18n37': '{% load i18n %}' - '{% trans "Page not found" as page_not_found %}' - '{% blocktrans %}Error: {{ page_not_found }}{% endblocktrans %}'}) + '{% translate "Page not found" as page_not_found %}' + '{% blocktranslate %}Error: {{ page_not_found }}{% endblocktranslate %}'}) def test_i18n37(self): with translation.override('de'): output = self.engine.render_to_string('i18n37') self.assertEqual(output, 'Error: Seite nicht gefunden') - # blocktrans tag with asvar + # blocktranslate tag with asvar @setup({'i18n39': '{% load i18n %}' - '{% blocktrans asvar page_not_found %}Page not found{% endblocktrans %}' + '{% blocktranslate asvar page_not_found %}Page not found{% endblocktranslate %}' '>{{ page_not_found }}<'}) def test_i18n39(self): with translation.override('de'): @@ -235,69 +235,73 @@ class I18nBlockTransTagTests(SimpleTestCase): self.assertEqual(output, '>Seite nicht gefunden<') @setup({'i18n40': '{% load i18n %}' - '{% trans "Page not found" as pg_404 %}' - '{% blocktrans with page_not_found=pg_404 asvar output %}' + '{% translate "Page not found" as pg_404 %}' + '{% blocktranslate with page_not_found=pg_404 asvar output %}' 'Error: {{ page_not_found }}' - '{% endblocktrans %}'}) + '{% endblocktranslate %}'}) def test_i18n40(self): output = self.engine.render_to_string('i18n40') self.assertEqual(output, '') @setup({'i18n41': '{% load i18n %}' - '{% trans "Page not found" as pg_404 %}' - '{% blocktrans with page_not_found=pg_404 asvar output %}' + '{% translate "Page not found" as pg_404 %}' + '{% blocktranslate with page_not_found=pg_404 asvar output %}' 'Error: {{ page_not_found }}' - '{% endblocktrans %}' + '{% endblocktranslate %}' '>{{ output }}<'}) def test_i18n41(self): with translation.override('de'): output = self.engine.render_to_string('i18n41') self.assertEqual(output, '>Error: Seite nicht gefunden<') - @setup({'template': '{% load i18n %}{% blocktrans asvar %}Yes{% endblocktrans %}'}) + @setup({'template': '{% load i18n %}{% blocktranslate asvar %}Yes{% endblocktranslate %}'}) def test_blocktrans_syntax_error_missing_assignment(self, tag_name): msg = "No argument provided to the '{}' tag for the asvar option.".format(tag_name) with self.assertRaisesMessage(TemplateSyntaxError, msg): self.engine.render_to_string('template') - @setup({'template': '{% load i18n %}{% blocktrans %}%s{% endblocktrans %}'}) + @setup({'template': '{% load i18n %}{% blocktranslate %}%s{% endblocktranslate %}'}) def test_blocktrans_tag_using_a_string_that_looks_like_str_fmt(self): output = self.engine.render_to_string('template') self.assertEqual(output, '%s') - @setup({'template': '{% load i18n %}{% blocktrans %}{% block b %} {% endblock %}{% endblocktrans %}'}) + @setup({'template': '{% load i18n %}{% blocktranslate %}{% block b %} {% endblock %}{% endblocktranslate %}'}) def test_with_block(self, tag_name): msg = "'{}' doesn't allow other block tags (seen 'block b') inside it".format(tag_name) with self.assertRaisesMessage(TemplateSyntaxError, msg): self.engine.render_to_string('template') - @setup({'template': '{% load i18n %}{% blocktrans %}{% for b in [1, 2, 3] %} {% endfor %}{% endblocktrans %}'}) + @setup({'template': ( + '{% load i18n %}' + '{% blocktranslate %}{% for b in [1, 2, 3] %} {% endfor %}' + '{% endblocktranslate %}' + )}) def test_with_for(self, tag_name): msg = "'{}' doesn't allow other block tags (seen 'for b in [1, 2, 3]') inside it".format(tag_name) with self.assertRaisesMessage(TemplateSyntaxError, msg): self.engine.render_to_string('template') - @setup({'template': '{% load i18n %}{% blocktrans with foo=bar with %}{{ foo }}{% endblocktrans %}'}) + @setup({'template': '{% load i18n %}{% blocktranslate with foo=bar with %}{{ foo }}{% endblocktranslate %}'}) def test_variable_twice(self): with self.assertRaisesMessage(TemplateSyntaxError, "The 'with' option was specified more than once"): self.engine.render_to_string('template', {'foo': 'bar'}) - @setup({'template': '{% load i18n %}{% blocktrans with %}{% endblocktrans %}'}) + @setup({'template': '{% load i18n %}{% blocktranslate with %}{% endblocktranslate %}'}) def test_no_args_with(self, tag_name): msg = '"with" in \'{}\' tag needs at least one keyword argument.'.format(tag_name) with self.assertRaisesMessage(TemplateSyntaxError, msg): self.engine.render_to_string('template') - @setup({'template': '{% load i18n %}{% blocktrans count a %}{% endblocktrans %}'}) + @setup({'template': '{% load i18n %}{% blocktranslate count a %}{% endblocktranslate %}'}) def test_count(self, tag_name): msg = '"count" in \'{}\' tag expected exactly one keyword argument.'.format(tag_name) with self.assertRaisesMessage(TemplateSyntaxError, msg): self.engine.render_to_string('template', {'a': [1, 2, 3]}) @setup({'template': ( - '{% load i18n %}{% blocktrans count count=var|length %}' + '{% load i18n %}{% blocktranslate count count=var|length %}' 'There is {{ count }} object. {% block a %} {% endblock %}' - '{% endblocktrans %}' + '{% endblocktranslate %}' )}) def test_plural_bad_syntax(self, tag_name): msg = "'{}' doesn't allow other block tags inside it".format(tag_name) @@ -305,133 +309,142 @@ class I18nBlockTransTagTests(SimpleTestCase): self.engine.render_to_string('template', {'var': [1, 2, 3]}) -class TranslationBlockTransTagTests(SimpleTestCase): - tag_name = 'blocktrans' +class TranslationBlockTranslateTagTests(SimpleTestCase): + tag_name = 'blocktranslate' def get_template(self, template_string): return Template( template_string.replace( - '{{% blocktrans ', + '{{% blocktranslate ', '{{% {}'.format(self.tag_name) ).replace( - '{{% endblocktrans %}}', + '{{% endblocktranslate %}}', '{{% end{} %}}'.format(self.tag_name) ) ) @override_settings(LOCALE_PATHS=extended_locale_paths) def test_template_tags_pgettext(self): - """{% blocktrans %} takes message contexts into account (#14806).""" + """{% blocktranslate %} takes message contexts into account (#14806).""" trans_real._active = Local() trans_real._translations = {} with translation.override('de'): # Nonexistent context - t = self.get_template('{% load i18n %}{% blocktrans context "nonexistent" %}May{% endblocktrans %}') + t = self.get_template( + '{% load i18n %}{% blocktranslate context "nonexistent" %}May' + '{% endblocktranslate %}' + ) rendered = t.render(Context()) self.assertEqual(rendered, 'May') # Existing context... using a literal - t = self.get_template('{% load i18n %}{% blocktrans context "month name" %}May{% endblocktrans %}') + t = self.get_template('{% load i18n %}{% blocktranslate context "month name" %}May{% endblocktranslate %}') rendered = t.render(Context()) self.assertEqual(rendered, 'Mai') - t = self.get_template('{% load i18n %}{% blocktrans context "verb" %}May{% endblocktrans %}') + t = self.get_template('{% load i18n %}{% blocktranslate context "verb" %}May{% endblocktranslate %}') rendered = t.render(Context()) self.assertEqual(rendered, 'Kann') # Using a variable - t = self.get_template('{% load i18n %}{% blocktrans context message_context %}May{% endblocktrans %}') + t = self.get_template( + '{% load i18n %}{% blocktranslate context message_context %}' + 'May{% endblocktranslate %}' + ) rendered = t.render(Context({'message_context': 'month name'})) self.assertEqual(rendered, 'Mai') - t = self.get_template('{% load i18n %}{% blocktrans context message_context %}May{% endblocktrans %}') + t = self.get_template( + '{% load i18n %}{% blocktranslate context message_context %}' + 'May{% endblocktranslate %}' + ) rendered = t.render(Context({'message_context': 'verb'})) self.assertEqual(rendered, 'Kann') # Using a filter t = self.get_template( - '{% load i18n %}{% blocktrans context message_context|lower %}May{% endblocktrans %}' + '{% load i18n %}{% blocktranslate context message_context|lower %}May{% endblocktranslate %}' ) rendered = t.render(Context({'message_context': 'MONTH NAME'})) self.assertEqual(rendered, 'Mai') t = self.get_template( - '{% load i18n %}{% blocktrans context message_context|lower %}May{% endblocktrans %}' + '{% load i18n %}{% blocktranslate context message_context|lower %}May{% endblocktranslate %}' ) rendered = t.render(Context({'message_context': 'VERB'})) self.assertEqual(rendered, 'Kann') # Using 'count' t = self.get_template( - '{% load i18n %}{% blocktrans count number=1 context "super search" %}' - '{{ number }} super result{% plural %}{{ number }} super results{% endblocktrans %}' + '{% load i18n %}{% blocktranslate count number=1 context "super search" %}' + '{{ number }} super result{% plural %}{{ number }} super results{% endblocktranslate %}' ) rendered = t.render(Context()) self.assertEqual(rendered, '1 Super-Ergebnis') t = self.get_template( - '{% load i18n %}{% blocktrans count number=2 context "super search" %}{{ number }}' - ' super result{% plural %}{{ number }} super results{% endblocktrans %}' + '{% load i18n %}{% blocktranslate count number=2 context "super search" %}{{ number }}' + ' super result{% plural %}{{ number }} super results{% endblocktranslate %}' ) rendered = t.render(Context()) self.assertEqual(rendered, '2 Super-Ergebnisse') t = self.get_template( - '{% load i18n %}{% blocktrans context "other super search" count number=1 %}' - '{{ number }} super result{% plural %}{{ number }} super results{% endblocktrans %}' + '{% load i18n %}{% blocktranslate context "other super search" count number=1 %}' + '{{ number }} super result{% plural %}{{ number }} super results{% endblocktranslate %}' ) rendered = t.render(Context()) self.assertEqual(rendered, '1 anderen Super-Ergebnis') t = self.get_template( - '{% load i18n %}{% blocktrans context "other super search" count number=2 %}' - '{{ number }} super result{% plural %}{{ number }} super results{% endblocktrans %}' + '{% load i18n %}{% blocktranslate context "other super search" count number=2 %}' + '{{ number }} super result{% plural %}{{ number }} super results{% endblocktranslate %}' ) rendered = t.render(Context()) self.assertEqual(rendered, '2 andere Super-Ergebnisse') # Using 'with' t = self.get_template( - '{% load i18n %}{% blocktrans with num_comments=5 context "comment count" %}' - 'There are {{ num_comments }} comments{% endblocktrans %}' + '{% load i18n %}{% blocktranslate with num_comments=5 context "comment count" %}' + 'There are {{ num_comments }} comments{% endblocktranslate %}' ) rendered = t.render(Context()) self.assertEqual(rendered, 'Es gibt 5 Kommentare') t = self.get_template( - '{% load i18n %}{% blocktrans with num_comments=5 context "other comment count" %}' - 'There are {{ num_comments }} comments{% endblocktrans %}' + '{% load i18n %}{% blocktranslate with num_comments=5 context "other comment count" %}' + 'There are {{ num_comments }} comments{% endblocktranslate %}' ) rendered = t.render(Context()) self.assertEqual(rendered, 'Andere: Es gibt 5 Kommentare') # Using trimmed t = self.get_template( - '{% load i18n %}{% blocktrans trimmed %}\n\nThere\n\t are 5 ' - '\n\n comments\n{% endblocktrans %}' + '{% load i18n %}{% blocktranslate trimmed %}\n\nThere\n\t are 5 ' + '\n\n comments\n{% endblocktranslate %}' ) rendered = t.render(Context()) self.assertEqual(rendered, 'There are 5 comments') t = self.get_template( - '{% load i18n %}{% blocktrans with num_comments=5 context "comment count" trimmed %}\n\n' - 'There are \t\n \t {{ num_comments }} comments\n\n{% endblocktrans %}' + '{% load i18n %}{% blocktranslate with num_comments=5 context "comment count" trimmed %}\n\n' + 'There are \t\n \t {{ num_comments }} comments\n\n{% endblocktranslate %}' ) rendered = t.render(Context()) self.assertEqual(rendered, 'Es gibt 5 Kommentare') t = self.get_template( - '{% load i18n %}{% blocktrans context "other super search" count number=2 trimmed %}\n' - '{{ number }} super \n result{% plural %}{{ number }} super results{% endblocktrans %}' + '{% load i18n %}{% blocktranslate context "other super search" count number=2 trimmed %}\n' + '{{ number }} super \n result{% plural %}{{ number }} super results{% endblocktranslate %}' ) rendered = t.render(Context()) self.assertEqual(rendered, '2 andere Super-Ergebnisse') # Misuses - msg = "Unknown argument for 'blocktrans' tag: %r." + msg = "Unknown argument for 'blocktranslate' tag: %r." with self.assertRaisesMessage(TemplateSyntaxError, msg % 'month="May"'): self.get_template( - '{% load i18n %}{% blocktrans context with month="May" %}{{ month }}{% endblocktrans %}' + '{% load i18n %}{% blocktranslate context with month="May" %}{{ month }}{% endblocktranslate %}' ) - msg = '"context" in %r tag expected exactly one argument.' % 'blocktrans' + msg = '"context" in %r tag expected exactly one argument.' % 'blocktranslate' with self.assertRaisesMessage(TemplateSyntaxError, msg): - self.get_template('{% load i18n %}{% blocktrans context %}{% endblocktrans %}') + self.get_template('{% load i18n %}{% blocktranslate context %}{% endblocktranslate %}') with self.assertRaisesMessage(TemplateSyntaxError, msg): self.get_template( - '{% load i18n %}{% blocktrans count number=2 context %}' + '{% load i18n %}{% blocktranslate count number=2 context %}' '{{ number }} super result{% plural %}{{ number }}' - ' super results{% endblocktrans %}' + ' super results{% endblocktranslate %}' ) @override_settings(LOCALE_PATHS=[os.path.join(here, 'other', 'locale')]) @@ -441,7 +454,7 @@ class TranslationBlockTransTagTests(SimpleTestCase): (%(person)s is translated as %(personne)s in fr.po). """ with translation.override('fr'): - t = Template('{% load i18n %}{% blocktrans %}My name is {{ person }}.{% endblocktrans %}') + t = Template('{% load i18n %}{% blocktranslate %}My name is {{ person }}.{% endblocktranslate %}') rendered = t.render(Context({'person': 'James'})) self.assertEqual(rendered, 'My name is James.') @@ -453,25 +466,25 @@ class TranslationBlockTransTagTests(SimpleTestCase): . """ with translation.override('fr'): - t = Template('{% load i18n %}{% blocktrans %}My other name is {{ person }}.{% endblocktrans %}') + t = Template('{% load i18n %}{% blocktranslate %}My other name is {{ person }}.{% endblocktranslate %}') rendered = t.render(Context({'person': 'James'})) self.assertEqual(rendered, 'My other name is James.') -class TranslationBlockTranslationTagTests(TranslationBlockTransTagTests): - tag_name = 'blocktranslation' +class TranslationBlockTransnTagTests(TranslationBlockTranslateTagTests): + tag_name = 'blocktrans' -class MultipleLocaleActivationBlockTransTests(MultipleLocaleActivationTestCase): - tag_name = 'blocktrans' +class MultipleLocaleActivationBlockTranslateTests(MultipleLocaleActivationTestCase): + tag_name = 'blocktranslate' def get_template(self, template_string): return Template( template_string.replace( - '{{% blocktrans ', + '{{% blocktranslate ', '{{% {}'.format(self.tag_name) ).replace( - '{{% endblocktrans %}}', + '{{% endblocktranslate %}}', '{{% end{} %}}'.format(self.tag_name) ) ) @@ -483,31 +496,31 @@ class MultipleLocaleActivationBlockTransTests(MultipleLocaleActivationTestCase): """ with translation.override('fr'): self.assertEqual( - self.get_template("{% load i18n %}{% blocktrans %}Yes{% endblocktrans %}").render(Context({})), + self.get_template("{% load i18n %}{% blocktranslate %}Yes{% endblocktranslate %}").render(Context({})), 'Oui' ) def test_multiple_locale_btrans(self): with translation.override('de'): - t = self.get_template("{% load i18n %}{% blocktrans %}No{% endblocktrans %}") + t = self.get_template("{% load i18n %}{% blocktranslate %}No{% endblocktranslate %}") with translation.override(self._old_language), translation.override('nl'): self.assertEqual(t.render(Context({})), 'Nee') def test_multiple_locale_deactivate_btrans(self): with translation.override('de', deactivate=True): - t = self.get_template("{% load i18n %}{% blocktrans %}No{% endblocktrans %}") + t = self.get_template("{% load i18n %}{% blocktranslate %}No{% endblocktranslate %}") with translation.override('nl'): self.assertEqual(t.render(Context({})), 'Nee') def test_multiple_locale_direct_switch_btrans(self): with translation.override('de'): - t = self.get_template("{% load i18n %}{% blocktrans %}No{% endblocktrans %}") + t = self.get_template("{% load i18n %}{% blocktranslate %}No{% endblocktranslate %}") with translation.override('nl'): self.assertEqual(t.render(Context({})), 'Nee') -class MultipleLocaleActivationBlockTranslationTests(MultipleLocaleActivationBlockTransTests): - tag_name = 'blocktranslation' +class MultipleLocaleActivationBlockTransTests(MultipleLocaleActivationBlockTranslateTests): + tag_name = 'blocktrans' class MiscTests(SimpleTestCase): @@ -516,21 +529,23 @@ class MiscTests(SimpleTestCase): def get_template(self, template_string): return Template( template_string.replace( - '{{% blocktrans ', + '{{% blocktranslate ', '{{% {}'.format(self.tag_name) ).replace( - '{{% endblocktrans %}}', + '{{% endblocktranslate %}}', '{{% end{} %}}'.format(self.tag_name) ) ) @override_settings(LOCALE_PATHS=extended_locale_paths) def test_percent_in_translatable_block(self): - t_sing = self.get_template("{% load i18n %}{% blocktrans %}The result was {{ percent }}%{% endblocktrans %}") + t_sing = self.get_template( + "{% load i18n %}{% blocktranslate %}The result was {{ percent }}%{% endblocktranslate %}" + ) t_plur = self.get_template( - "{% load i18n %}{% blocktrans count num as number %}" + "{% load i18n %}{% blocktranslate count num as number %}" "{{ percent }}% represents {{ num }} object{% plural %}" - "{{ percent }}% represents {{ num }} objects{% endblocktrans %}" + "{{ percent }}% represents {{ num }} objects{% endblocktranslate %}" ) with translation.override('de'): self.assertEqual(t_sing.render(Context({'percent': 42})), 'Das Ergebnis war 42%') @@ -544,12 +559,12 @@ class MiscTests(SimpleTestCase): or plural. """ t_sing = self.get_template( - "{% load i18n %}{% blocktrans %}There are %(num_comments)s comments{% endblocktrans %}" + "{% load i18n %}{% blocktranslate %}There are %(num_comments)s comments{% endblocktranslate %}" ) t_plur = self.get_template( - "{% load i18n %}{% blocktrans count num as number %}" + "{% load i18n %}{% blocktranslate count num as number %}" "%(percent)s% represents {{ num }} object{% plural %}" - "%(percent)s% represents {{ num }} objects{% endblocktrans %}" + "%(percent)s% represents {{ num }} objects{% endblocktranslate %}" ) with translation.override('de'): # Strings won't get translated as they don't match after escaping % |
