summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMike Hansen <mike@rover.com>2019-09-23 08:31:21 -0700
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-12-18 13:15:38 +0100
commit35d36d946272bed06a3d7c7cd4e5b71b613e7a4f (patch)
treee6c774f841dc77ca311be6ecfad9c5d7ef790336 /tests
parentd291c72bf24387e4abe8d9883ebe9c69abdd26d0 (diff)
Refs #30585 -- Updated project templates and tests to use (block)translate tags.
Diffstat (limited to 'tests')
-rw-r--r--tests/admin_views/templates/admin/admin_views/article/actions.html2
-rw-r--r--tests/admin_views/templates/admin/admin_views/article/change_form_object_tools.html2
-rw-r--r--tests/admin_views/templates/admin/admin_views/article/change_list_object_tools.html2
-rw-r--r--tests/admin_views/templates/admin/admin_views/article/change_list_results.html6
-rw-r--r--tests/admin_views/templates/admin/admin_views/article/date_hierarchy.html2
-rw-r--r--tests/admin_views/templates/admin/admin_views/article/pagination.html4
-rw-r--r--tests/admin_views/templates/admin/admin_views/article/search_form.html4
-rw-r--r--tests/admin_views/templates/admin/admin_views/article/submit_line.html2
-rw-r--r--tests/i18n/commands/ignore_dir/ignored.html2
-rw-r--r--tests/i18n/commands/templates/comments.thtml20
-rw-r--r--tests/i18n/commands/templates/plural.djtpl2
-rw-r--r--tests/i18n/commands/templates/subdir/ignored.html2
-rw-r--r--tests/i18n/commands/templates/template_with_error.tpl4
-rw-r--r--tests/i18n/commands/templates/test.html81
-rw-r--r--tests/i18n/commands/templates/xxx_ignored.html2
-rw-r--r--tests/i18n/sampleproject/templates/percents.html16
-rwxr-xr-xtests/i18n/sampleproject/update_catalogs.py3
-rw-r--r--tests/i18n/test_extraction.py38
-rw-r--r--tests/i18n/test_percents.py44
-rw-r--r--tests/template_tests/syntax_tests/i18n/test_blocktranslate.py247
-rw-r--r--tests/template_tests/syntax_tests/i18n/test_translate.py78
-rw-r--r--tests/template_tests/syntax_tests/test_invalid_string.py2
22 files changed, 290 insertions, 275 deletions
diff --git a/tests/admin_views/templates/admin/admin_views/article/actions.html b/tests/admin_views/templates/admin/admin_views/article/actions.html
index 9aa238fd2a..d66ad304a2 100644
--- a/tests/admin_views/templates/admin/admin_views/article/actions.html
+++ b/tests/admin_views/templates/admin/admin_views/article/actions.html
@@ -2,5 +2,5 @@
{% load i18n %}
{% block actions-submit %}
-<button type="submit" class="button override-actions" title="{% trans "Run the selected action" %}" name="index" value="{{ action_index|default:0 }}">{% trans "Go" %}</button>
+<button type="submit" class="button override-actions" title="{% translate "Run the selected action" %}" name="index" value="{{ action_index|default:0 }}">{% translate "Go" %}</button>
{% endblock %}
diff --git a/tests/admin_views/templates/admin/admin_views/article/change_form_object_tools.html b/tests/admin_views/templates/admin/admin_views/article/change_form_object_tools.html
index 609974bb95..d141664daf 100644
--- a/tests/admin_views/templates/admin/admin_views/article/change_form_object_tools.html
+++ b/tests/admin_views/templates/admin/admin_views/article/change_form_object_tools.html
@@ -2,6 +2,6 @@
{% load i18n admin_urls %}
{% block object-tools-items %}
-<li><a href="#" id="change-form-export" class="override-change_form_object_tools change-form-object-tools-item">{% trans "Export" %}</a></li>
+<li><a href="#" id="change-form-export" class="override-change_form_object_tools change-form-object-tools-item">{% translate "Export" %}</a></li>
{{ block.super }}
{% endblock %}
diff --git a/tests/admin_views/templates/admin/admin_views/article/change_list_object_tools.html b/tests/admin_views/templates/admin/admin_views/article/change_list_object_tools.html
index 1a9be91952..b366807da4 100644
--- a/tests/admin_views/templates/admin/admin_views/article/change_list_object_tools.html
+++ b/tests/admin_views/templates/admin/admin_views/article/change_list_object_tools.html
@@ -2,6 +2,6 @@
{% load i18n admin_urls %}
{% block object-tools-items %}
-<li><a href="#" id="change-list-export" class="override-change_list_object_tools change-list-object-tools-item">{% trans "Export" %}</a></li>
+<li><a href="#" id="change-list-export" class="override-change_list_object_tools change-list-object-tools-item">{% translate "Export" %}</a></li>
{{ block.super }}
{% endblock %}
diff --git a/tests/admin_views/templates/admin/admin_views/article/change_list_results.html b/tests/admin_views/templates/admin/admin_views/article/change_list_results.html
index ceb581f8ef..ca36f3abcf 100644
--- a/tests/admin_views/templates/admin/admin_views/article/change_list_results.html
+++ b/tests/admin_views/templates/admin/admin_views/article/change_list_results.html
@@ -14,9 +14,9 @@
{% if header.sortable %}
{% if header.sort_priority > 0 %}
<div class="sortoptions">
- <a class="sortremove" href="{{ header.url_remove }}" title="{% trans "Remove from sorting" %}"></a>
- {% if num_sorted_fields > 1 %}<span class="sortpriority" title="{% blocktrans with priority_number=header.sort_priority %}Sorting priority: {{ priority_number }}{% endblocktrans %}">{{ header.sort_priority }}</span>{% endif %}
- <a href="{{ header.url_toggle }}" class="toggle {% if header.ascending %}ascending{% else %}descending{% endif %}" title="{% trans "Toggle sorting" %}"></a>
+ <a class="sortremove" href="{{ header.url_remove }}" title="{% translate "Remove from sorting" %}"></a>
+ {% if num_sorted_fields > 1 %}<span class="sortpriority" title="{% blocktranslate with priority_number=header.sort_priority %}Sorting priority: {{ priority_number }}{% endblocktranslate %}">{{ header.sort_priority }}</span>{% endif %}
+ <a href="{{ header.url_toggle }}" class="toggle {% if header.ascending %}ascending{% else %}descending{% endif %}" title="{% translate "Toggle sorting" %}"></a>
</div>
{% endif %}
{% endif %}
diff --git a/tests/admin_views/templates/admin/admin_views/article/date_hierarchy.html b/tests/admin_views/templates/admin/admin_views/article/date_hierarchy.html
index de1cb747b5..8f76bea8f9 100644
--- a/tests/admin_views/templates/admin/admin_views/article/date_hierarchy.html
+++ b/tests/admin_views/templates/admin/admin_views/article/date_hierarchy.html
@@ -5,5 +5,5 @@
<select id="date-selector" class="override-date_hierarchy">{% for choice in choices %}
<option{% if choice.link %} value="{{ choice.link }}"{% endif %}>{{ choice.title }}</option>
{% endfor %}</select>
-<button id="date-selected">{% trans "Go" %}</button>
+<button id="date-selected">{% translate "Go" %}</button>
{% endblock %}
diff --git a/tests/admin_views/templates/admin/admin_views/article/pagination.html b/tests/admin_views/templates/admin/admin_views/article/pagination.html
index e072cacd3c..e712b7d2d7 100644
--- a/tests/admin_views/templates/admin/admin_views/article/pagination.html
+++ b/tests/admin_views/templates/admin/admin_views/article/pagination.html
@@ -7,6 +7,6 @@
{% endfor %}
{% endif %}
{{ cl.result_count }} {% if cl.result_count == 1 %}{{ cl.opts.verbose_name }}{% else %}{{ cl.opts.verbose_name_plural }}{% endif %}
-{% if show_all_url %}&nbsp;&nbsp;<a href="{{ show_all_url }}" class="showall">{% trans 'Show all' %}</a>{% endif %}
-{% if cl.formset and cl.result_count %}<input type="submit" name="_save" class="default" value="{% trans 'Save' %}"/>{% endif %}
+{% if show_all_url %}&nbsp;&nbsp;<a href="{{ show_all_url }}" class="showall">{% translate 'Show all' %}</a>{% endif %}
+{% if cl.formset and cl.result_count %}<input type="submit" name="_save" class="default" value="{% translate 'Save' %}"/>{% endif %}
</p>
diff --git a/tests/admin_views/templates/admin/admin_views/article/search_form.html b/tests/admin_views/templates/admin/admin_views/article/search_form.html
index 5b5e6a58f6..eef986cb30 100644
--- a/tests/admin_views/templates/admin/admin_views/article/search_form.html
+++ b/tests/admin_views/templates/admin/admin_views/article/search_form.html
@@ -4,9 +4,9 @@
<div><!-- DIV needed for valid HTML -->
<label for="searchbar"><img src="{% static "admin/img/search.svg" %}" alt="Search" /></label>
<input type="text" size="40" name="{{ search_var }}" value="{{ cl.query }}" id="searchbar" autofocus />
-<input type="submit" value="{% trans 'Search' %}" />
+<input type="submit" value="{% translate 'Search' %}" />
{% if show_result_count %}
- <span class="small quiet">{% blocktrans count counter=cl.result_count %}{{ counter }} result{% plural %}{{ counter }} results{% endblocktrans %} (<a href="?{% if cl.is_popup %}_popup=1{% endif %}">{% if cl.show_full_result_count %}{% blocktrans with full_result_count=cl.full_result_count %}{{ full_result_count }} total{% endblocktrans %}{% else %}{% trans "Show all" %}{% endif %}</a>)</span>
+ <span class="small quiet">{% blocktranslate count counter=cl.result_count %}{{ counter }} result{% plural %}{{ counter }} results{% endblocktranslate %} (<a href="?{% if cl.is_popup %}_popup=1{% endif %}">{% if cl.show_full_result_count %}{% blocktranslate with full_result_count=cl.full_result_count %}{{ full_result_count }} total{% endblocktranslate %}{% else %}{% translate "Show all" %}{% endif %}</a>)</span>
{% endif %}
{% for pair in cl.params.items %}
{% if pair.0 != search_var %}<input type="hidden" name="{{ pair.0 }}" value="{{ pair.1 }}"/>{% endif %}
diff --git a/tests/admin_views/templates/admin/admin_views/article/submit_line.html b/tests/admin_views/templates/admin/admin_views/article/submit_line.html
index 4a2ca08890..97554b5571 100644
--- a/tests/admin_views/templates/admin/admin_views/article/submit_line.html
+++ b/tests/admin_views/templates/admin/admin_views/article/submit_line.html
@@ -2,6 +2,6 @@
{% load i18n admin_urls %}
{% block submit-row %}
-{% if show_publish %}<input type="submit" value="{% trans 'Publish' %}" class="default" name="_publish" />{% endif %}
+{% if show_publish %}<input type="submit" value="{% translate 'Publish' %}" class="default" name="_publish" />{% endif %}
{{ block.super }}
{% endblock %}
diff --git a/tests/i18n/commands/ignore_dir/ignored.html b/tests/i18n/commands/ignore_dir/ignored.html
index 6a296787ef..037df44020 100644
--- a/tests/i18n/commands/ignore_dir/ignored.html
+++ b/tests/i18n/commands/ignore_dir/ignored.html
@@ -1,2 +1,2 @@
{% load i18n %}
-{% trans "This should be ignored." %}
+{% translate "This should be ignored." %}
diff --git a/tests/i18n/commands/templates/comments.thtml b/tests/i18n/commands/templates/comments.thtml
index 90eb5f1792..50249d911e 100644
--- a/tests/i18n/commands/templates/comments.thtml
+++ b/tests/i18n/commands/templates/comments.thtml
@@ -1,13 +1,13 @@
{% load i18n %}
-{# ignored comment #1 #}{% trans "Translatable literal #9a" %}
-{# Translators: ignored i18n comment #1 #}{% trans "Translatable literal #9b" %}
-{# Translators: ignored i18n comment #2 #}{# ignored comment #2 #}{% trans "Translatable literal #9c" %}
-{# ignored comment #3 #}{# Translators: ignored i18n comment #3 #}{% trans "Translatable literal #9d" %}
-{# ignored comment #4 #}{% trans "Translatable literal #9e" %}{# ignored comment #5 #}
-{# Translators: ignored i18n comment #4 #}{% trans "Translatable literal #9f" %}{# Translators: valid i18n comment #5 #}
-{% trans "Translatable literal #9g" %}{# Translators: valid i18n comment #6 #}
-{# ignored comment #6 #}{% trans "Translatable literal #9h" %}{# Translators: valid i18n comment #7 #}
-{% trans "Translatable literal #9i" %}
+{# ignored comment #1 #}{% translate "Translatable literal #9a" %}
+{# Translators: ignored i18n comment #1 #}{% translate "Translatable literal #9b" %}
+{# Translators: ignored i18n comment #2 #}{# ignored comment #2 #}{% translate "Translatable literal #9c" %}
+{# ignored comment #3 #}{# Translators: ignored i18n comment #3 #}{% translate "Translatable literal #9d" %}
+{# ignored comment #4 #}{% translate "Translatable literal #9e" %}{# ignored comment #5 #}
+{# Translators: ignored i18n comment #4 #}{% translate "Translatable literal #9f" %}{# Translators: valid i18n comment #5 #}
+{% translate "Translatable literal #9g" %}{# Translators: valid i18n comment #6 #}
+{# ignored comment #6 #}{% translate "Translatable literal #9h" %}{# Translators: valid i18n comment #7 #}
+{% translate "Translatable literal #9i" %}
{# Translators: valid i18n comment #8 #}{# Translators: valid i18n comment #9 #}
-{% trans "Translatable literal #9j" %}
+{% translate "Translatable literal #9j" %}
diff --git a/tests/i18n/commands/templates/plural.djtpl b/tests/i18n/commands/templates/plural.djtpl
index fc37855d20..f01565bf18 100644
--- a/tests/i18n/commands/templates/plural.djtpl
+++ b/tests/i18n/commands/templates/plural.djtpl
@@ -3,6 +3,6 @@
This file has a literal with plural forms. When processed first, makemessages
shouldn't create a .po file with duplicate `Plural-Forms` headers
{% endcomment %}
-{% blocktrans count number=3 %}{{ number }} Bar{% plural %}{{ number }} Bars{% endblocktrans %}
+{% blocktranslate count number=3 %}{{ number }} Bar{% plural %}{{ number }} Bars{% endblocktranslate %}
{% translate 'First `translate`, then `blocktranslate` with a plural' %}
diff --git a/tests/i18n/commands/templates/subdir/ignored.html b/tests/i18n/commands/templates/subdir/ignored.html
index d36a6fe881..86fdecc94a 100644
--- a/tests/i18n/commands/templates/subdir/ignored.html
+++ b/tests/i18n/commands/templates/subdir/ignored.html
@@ -1,2 +1,2 @@
{% load i18n %}
-{% trans "This subdir should be ignored too." %}
+{% translate "This subdir should be ignored too." %}
diff --git a/tests/i18n/commands/templates/template_with_error.tpl b/tests/i18n/commands/templates/template_with_error.tpl
index c2b93bdd06..d427098bdf 100644
--- a/tests/i18n/commands/templates/template_with_error.tpl
+++ b/tests/i18n/commands/templates/template_with_error.tpl
@@ -1,3 +1,3 @@
{% load i18n %}
-<p>This template contains an error (no endblocktrans)</p>
-<p>{% blocktrans %}This should fail{% blocktrans %}</p>
+<p>This template contains an error (no endblocktranslate)</p>
+<p>{% blocktranslate %}This should fail{% blocktranslate %}</p>
diff --git a/tests/i18n/commands/templates/test.html b/tests/i18n/commands/templates/test.html
index 0671a68860..acac1a1149 100644
--- a/tests/i18n/commands/templates/test.html
+++ b/tests/i18n/commands/templates/test.html
@@ -2,103 +2,104 @@
{% comment %}Translators: Django comment block for translators
string's meaning unveiled
{% endcomment %}
-{% trans "This literal should be included." %}
-{% trans "This literal should also be included wrapped or not wrapped depending on the use of the --no-wrap option." %}
+{% translate "This literal should be included." %}
+{% translate "This literal should also be included wrapped or not wrapped depending on the use of the --no-wrap option." %}
{% comment %}Some random comment
Some random comment
Translators: One-line translator comment #1
{% endcomment %}
-{% trans "Translatable literal #1a" %}
+{% translate "Translatable literal #1a" %}
{% comment %}Some random comment
Some random comment
Translators: Two-line translator comment #1
continued here.
{% endcomment %}
-{% trans "Translatable literal #1b" %}
+{% translate "Translatable literal #1b" %}
{% comment %}Some random comment
Translators: One-line translator comment #2
{% endcomment %}
-{% trans "Translatable literal #2a" %}
+{% translate "Translatable literal #2a" %}
{% comment %}Some random comment
Translators: Two-line translator comment #2
continued here.
{% endcomment %}
-{% trans "Translatable literal #2b" %}
+{% translate "Translatable literal #2b" %}
{% comment %}
Translators: One-line translator comment #3
{% endcomment %}
-{% trans "Translatable literal #3a" %}
+{% translate "Translatable literal #3a" %}
{% comment %}
Translators: Two-line translator comment #3
continued here.
{% endcomment %}
-{% trans "Translatable literal #3b" %}
+{% translate "Translatable literal #3b" %}
{% comment %} Translators: One-line translator comment #4{% endcomment %}
-{% trans "Translatable literal #4a" %}
+{% translate "Translatable literal #4a" %}
{% comment %} Translators: Two-line translator comment #4
continued here.{% endcomment %}
-{% trans "Translatable literal #4b" %}
+{% translate "Translatable literal #4b" %}
{% comment %} Translators: One-line translator comment #5 -- with non ASCII characters: áéíóúö{% endcomment %}
-{% trans "Translatable literal #5a" %}
+{% translate "Translatable literal #5a" %}
{% comment %} Translators: Two-line translator comment #5 -- with non ASCII characters: áéíóúö
continued here.{% endcomment %}
-{% trans "Translatable literal #6b" %}
+{% translate "Translatable literal #6b" %}
-{% trans "Translatable literal #7a" context "Special trans context #1" %}
-{% trans "Translatable literal #7b" as var context "Special trans context #2" %}
-{% trans "Translatable literal #7c" context "Special trans context #3" as var %}
+{% translate "Translatable literal #7a" context "Special trans context #1" %}
+{% translate "Translatable literal #7b" as var context "Special trans context #2" %}
+{% translate "Translatable literal #7c" context "Special trans context #3" as var %}
-{% trans "Translatable literal #7.1a" | upper context "context #7.1a" %}
-{% trans "Translatable literal #7.1b" |upper as var context "context #7.1b" %}
-{% trans "Translatable literal #7.1c"| upper context "context #7.1c" as var %}
+{% translate "Translatable literal #7.1a" | upper context "context #7.1a" %}
+{% translate "Translatable literal #7.1b" |upper as var context "context #7.1b" %}
+{% translate "Translatable literal #7.1c"| upper context "context #7.1c" as var %}
-{% trans "Translatable literal #7.1d"|add:" foo" context "context #7.1d" %}
-{% trans "Translatable literal #7.1e"|add:' ûè本' as var context "context #7.1e" %}
+{% translate "Translatable literal #7.1d"|add:" foo" context "context #7.1d" %}
+{% translate "Translatable literal #7.1e"|add:' ûè本' as var context "context #7.1e" %}
{% with foo=" foo" %}
- {% trans "Translatable literal #7.1f"|add:foo context "context #7.1f" as var %}
+ {% translate "Translatable literal #7.1f"|add:foo context "context #7.1f" as var %}
{% endwith %}
-{% trans "Translatable literal #7.1g"|add:2 context "context #7.1g" as var %}
-{% trans "Translatable literal #7.1h" | add:"foo" | add:2 context "context #7.1h" as var %}
+{% translate "Translatable literal #7.1g"|add:2 context "context #7.1g" as var %}
+{% translate "Translatable literal #7.1h" | add:"foo" | add:2 context "context #7.1h" as var %}
<!-- Source file inside a msgid, should be left as-is. -->
-{% trans "#: templates/test.html.py" %}
+{% translate "#: templates/test.html.py" %}
<!-- Deliberate duplicated string. -->
-{% trans "This literal should be included." %}
+{% translate "This literal should be included." %}
-{% blocktrans context "Special blocktrans context #1" %}Translatable literal #8a{% endblocktrans %}
-{% blocktrans count 2 context "Special blocktrans context #2" %}Translatable literal #8b-singular{% plural %}Translatable literal #8b-plural{% endblocktrans %}
-{% blocktrans context "Special blocktrans context #3" count 2 %}Translatable literal #8c-singular{% plural %}Translatable literal #8c-plural{% endblocktrans %}
-{% blocktrans with a=1 context "Special blocktrans context #4" %}Translatable literal #8d {{ a }}{% endblocktrans %}
+{% blocktranslate context "Special blocktranslate context #1" %}Translatable literal #8a{% endblocktranslate %}
+{% blocktranslate count 2 context "Special blocktranslate context #2" %}Translatable literal #8b-singular{% plural %}Translatable literal #8b-plural{% endblocktranslate %}
+{% blocktranslate context "Special blocktranslate context #3" count 2 %}Translatable literal #8c-singular{% plural %}Translatable literal #8c-plural{% endblocktranslate %}
+{% blocktranslate with a=1 context "Special blocktranslate context #4" %}Translatable literal #8d {{ a }}{% endblocktranslate %}
-{% trans "Translatable literal with context wrapped in single quotes" context 'Context wrapped in single quotes' as var %}
-{% trans "Translatable literal with context wrapped in double quotes" context "Context wrapped in double quotes" as var %}
-{% blocktrans context 'Special blocktrans context wrapped in single quotes' %}Translatable literal with context wrapped in single quotes{% endblocktrans %}
-{% blocktrans context "Special blocktrans context wrapped in double quotes" %}Translatable literal with context wrapped in double quotes{% endblocktrans %}
+{% translate "Translatable literal with context wrapped in single quotes" context 'Context wrapped in single quotes' as var %}
+{% translate "Translatable literal with context wrapped in double quotes" context "Context wrapped in double quotes" as var %}
+{% blocktranslate context 'Special blocktranslate context wrapped in single quotes' %}Translatable literal with context wrapped in single quotes{% endblocktranslate %}
+{% blocktranslate context "Special blocktranslate context wrapped in double quotes" %}Translatable literal with context wrapped in double quotes{% endblocktranslate %}
-{% blocktranslate %}blocktranslate text{% endblocktranslate %}
-{% translate "translate text" %}
+{# Backwards compatability tests #}
+{% blocktrans %}blocktrans text{% endblocktrans %}
+{% trans "trans text" %}
{# BasicExtractorTests.test_blocktranslate_trimmed #}
{% blocktranslate %}
Text with a few
line breaks.
-{% endblocktrans %}
-{% blocktrans trimmed %}
+{% endblocktranslate %}
+{% blocktranslate trimmed %}
Again some text with a few
line breaks, this time
should be trimmed.
-{% endblocktrans %}
-{% trans "Get my line number" %}
+{% endblocktranslate %}
+{% translate "Get my line number" %}
{% blocktranslate trimmed count counter=mylist|length %}
First `translate`, then `blocktranslate` with a plural
@@ -106,4 +107,4 @@ First `translate`, then `blocktranslate` with a plural
Plural for a `translate` and `blocktranslate` collision case
{% endblocktranslate %}
-{% trans "Non-breaking space :" %}
+{% translate "Non-breaking space :" %}
diff --git a/tests/i18n/commands/templates/xxx_ignored.html b/tests/i18n/commands/templates/xxx_ignored.html
index a41cbe202a..52e57c5a2b 100644
--- a/tests/i18n/commands/templates/xxx_ignored.html
+++ b/tests/i18n/commands/templates/xxx_ignored.html
@@ -1,2 +1,2 @@
{% load i18n %}
-{% trans "This should be ignored too." %}
+{% translate "This should be ignored too." %}
diff --git a/tests/i18n/sampleproject/templates/percents.html b/tests/i18n/sampleproject/templates/percents.html
index 506c0610c5..48a543a864 100644
--- a/tests/i18n/sampleproject/templates/percents.html
+++ b/tests/i18n/sampleproject/templates/percents.html
@@ -1,12 +1,12 @@
{% load i18n %}
-{% trans "Literal with a percent symbol at the end %" %}
-{% trans "Literal with a percent % symbol in the middle" %}
+{% translate "Literal with a percent symbol at the end %" %}
+{% translate "Literal with a percent % symbol in the middle" %}
-{% trans "It is 100%" %}
-{% trans "It is 100%" context "female" %}
-{% trans "Looks like a str fmt spec %s but should not be interpreted as such" %}
-{% trans "Looks like a str fmt spec % o but should not be interpreted as such" %}
+{% translate "It is 100%" %}
+{% translate "It is 100%" context "female" %}
+{% translate "Looks like a str fmt spec %s but should not be interpreted as such" %}
+{% translate "Looks like a str fmt spec % o but should not be interpreted as such" %}
-{% trans "1 percent sign %, 2 percent signs %%, 3 percent signs %%%" %}
-{% blocktrans with name="Simon" %}{{name}} says: 1 percent sign %, 2 percent signs %%{% endblocktrans %}
+{% translate "1 percent sign %, 2 percent signs %%, 3 percent signs %%%" %}
+{% blocktranslate with name="Simon" %}{{name}} says: 1 percent sign %, 2 percent signs %%{% endblocktranslate %}
diff --git a/tests/i18n/sampleproject/update_catalogs.py b/tests/i18n/sampleproject/update_catalogs.py
index 8c57307f47..55bf1656a2 100755
--- a/tests/i18n/sampleproject/update_catalogs.py
+++ b/tests/i18n/sampleproject/update_catalogs.py
@@ -13,8 +13,7 @@ blocktranslate. This issue is difficult to debug, it could be a problem with
extraction, interpolation, or both.
How this script helps:
- * Add {% translate "Two %% Three %%%" %} and blocktranslate equivalent to
- templates.
+ * Add {% translate "Two %% Three %%%" %} and blocktranslate equivalent to templates.
* Run this script.
* Test extraction - verify the new msgid in sampleproject's django.po.
* Add a translation to sampleproject's django.po.
diff --git a/tests/i18n/test_extraction.py b/tests/i18n/test_extraction.py
index db66ea1db5..709a6133f5 100644
--- a/tests/i18n/test_extraction.py
+++ b/tests/i18n/test_extraction.py
@@ -197,7 +197,7 @@ class BasicExtractorTests(ExtractorTests):
def test_extraction_error(self):
msg = (
- 'Translation blocks must not include other block tags: blocktrans '
+ 'Translation blocks must not include other block tags: blocktranslate '
'(file %s, line 3)' % os.path.join('templates', 'template_with_error.tpl')
)
with self.assertRaisesMessage(SyntaxError, msg):
@@ -224,14 +224,14 @@ class BasicExtractorTests(ExtractorTests):
def test_template_message_context_extractor(self):
"""
- Message contexts are correctly extracted for the {% trans %} and
- {% blocktrans %} template tags (#14806).
+ Message contexts are correctly extracted for the {% translate %} and
+ {% blocktranslate %} template tags (#14806).
"""
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE) as fp:
po_contents = fp.read()
- # {% trans %}
+ # {% translate %}
self.assertIn('msgctxt "Special trans context #1"', po_contents)
self.assertMsgId("Translatable literal #7a", po_contents)
self.assertIn('msgctxt "Special trans context #2"', po_contents)
@@ -239,39 +239,39 @@ class BasicExtractorTests(ExtractorTests):
self.assertIn('msgctxt "Special trans context #3"', po_contents)
self.assertMsgId("Translatable literal #7c", po_contents)
- # {% trans %} with a filter
+ # {% translate %} with a filter
for minor_part in 'abcdefgh': # Iterate from #7.1a to #7.1h template markers
self.assertIn('msgctxt "context #7.1{}"'.format(minor_part), po_contents)
self.assertMsgId('Translatable literal #7.1{}'.format(minor_part), po_contents)
- # {% blocktrans %}
- self.assertIn('msgctxt "Special blocktrans context #1"', po_contents)
+ # {% blocktranslate %}
+ self.assertIn('msgctxt "Special blocktranslate context #1"', po_contents)
self.assertMsgId("Translatable literal #8a", po_contents)
- self.assertIn('msgctxt "Special blocktrans context #2"', po_contents)
+ self.assertIn('msgctxt "Special blocktranslate context #2"', po_contents)
self.assertMsgId("Translatable literal #8b-singular", po_contents)
self.assertIn("Translatable literal #8b-plural", po_contents)
- self.assertIn('msgctxt "Special blocktrans context #3"', po_contents)
+ self.assertIn('msgctxt "Special blocktranslate context #3"', po_contents)
self.assertMsgId("Translatable literal #8c-singular", po_contents)
self.assertIn("Translatable literal #8c-plural", po_contents)
- self.assertIn('msgctxt "Special blocktrans context #4"', po_contents)
+ self.assertIn('msgctxt "Special blocktranslate context #4"', po_contents)
self.assertMsgId("Translatable literal #8d %(a)s", po_contents)
- # {% translate %} and {% blocktranslate %}
- self.assertMsgId('translate text', po_contents)
- self.assertMsgId('blocktranslate text', po_contents)
+ # {% trans %} and {% blocktrans %}
+ self.assertMsgId('trans text', po_contents)
+ self.assertMsgId('blocktrans text', po_contents)
def test_context_in_single_quotes(self):
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE) as fp:
po_contents = fp.read()
- # {% trans %}
+ # {% translate %}
self.assertIn('msgctxt "Context wrapped in double quotes"', po_contents)
self.assertIn('msgctxt "Context wrapped in single quotes"', po_contents)
- # {% blocktrans %}
- self.assertIn('msgctxt "Special blocktrans context wrapped in double quotes"', po_contents)
- self.assertIn('msgctxt "Special blocktrans context wrapped in single quotes"', po_contents)
+ # {% blocktranslate %}
+ self.assertIn('msgctxt "Special blocktranslate context wrapped in double quotes"', po_contents)
+ self.assertIn('msgctxt "Special blocktranslate context wrapped in single quotes"', po_contents)
def test_template_comments(self):
"""Template comment tags on the same line of other constructs (#19552)"""
@@ -535,8 +535,8 @@ class CopyPluralFormsExtractorTests(ExtractorTests):
def test_translate_and_plural_blocktranslate_collision(self):
"""
Ensures a correct workaround for the gettext bug when handling a literal
- found inside a {% trans %} tag and also in another file inside a
- {% blocktrans %} with a plural (#17375).
+ found inside a {% translate %} tag and also in another file inside a
+ {% blocktranslate %} with a plural (#17375).
"""
management.call_command('makemessages', locale=[LOCALE], extensions=['html', 'djtpl'], verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
diff --git a/tests/i18n/test_percents.py b/tests/i18n/test_percents.py
index 6f36d4669a..5362ace0a7 100644
--- a/tests/i18n/test_percents.py
+++ b/tests/i18n/test_percents.py
@@ -61,7 +61,7 @@ class RenderingTemplatesWithPercentSigns(FrenchTestCase):
"""
Test rendering of templates that use percent signs.
- Ensures both trans and blocktrans tags behave consistently.
+ Ensures both translate and blocktranslate tags behave consistently.
Refs #11240, #11966, #24257
"""
@@ -69,62 +69,62 @@ class RenderingTemplatesWithPercentSigns(FrenchTestCase):
def test_translates_with_a_percent_symbol_at_the_end(self):
expected = 'Littérale avec un symbole de pour cent à la fin %'
- trans_tpl = Template('{% load i18n %}{% trans "Literal with a percent symbol at the end %" %}')
+ trans_tpl = Template('{% load i18n %}{% translate "Literal with a percent symbol at the end %" %}')
self.assertEqual(trans_tpl.render(Context({})), expected)
block_tpl = Template(
- '{% load i18n %}{% blocktrans %}Literal with a percent symbol at '
- 'the end %{% endblocktrans %}'
+ '{% load i18n %}{% blocktranslate %}Literal with a percent symbol at '
+ 'the end %{% endblocktranslate %}'
)
self.assertEqual(block_tpl.render(Context({})), expected)
def test_translates_with_percent_symbol_in_the_middle(self):
expected = 'Pour cent littérale % avec un symbole au milieu'
- trans_tpl = Template('{% load i18n %}{% trans "Literal with a percent % symbol in the middle" %}')
+ trans_tpl = Template('{% load i18n %}{% translate "Literal with a percent % symbol in the middle" %}')
self.assertEqual(trans_tpl.render(Context({})), expected)
block_tpl = Template(
- '{% load i18n %}{% blocktrans %}Literal with a percent % symbol '
- 'in the middle{% endblocktrans %}'
+ '{% load i18n %}{% blocktranslate %}Literal with a percent % symbol '
+ 'in the middle{% endblocktranslate %}'
)
self.assertEqual(block_tpl.render(Context({})), expected)
def test_translates_with_percent_symbol_using_context(self):
- trans_tpl = Template('{% load i18n %}{% trans "It is 100%" %}')
+ trans_tpl = Template('{% load i18n %}{% translate "It is 100%" %}')
self.assertEqual(trans_tpl.render(Context({})), 'Il est de 100%')
- trans_tpl = Template('{% load i18n %}{% trans "It is 100%" context "female" %}')
+ trans_tpl = Template('{% load i18n %}{% translate "It is 100%" context "female" %}')
self.assertEqual(trans_tpl.render(Context({})), 'Elle est de 100%')
- block_tpl = Template('{% load i18n %}{% blocktrans %}It is 100%{% endblocktrans %}')
+ block_tpl = Template('{% load i18n %}{% blocktranslate %}It is 100%{% endblocktranslate %}')
self.assertEqual(block_tpl.render(Context({})), 'Il est de 100%')
- block_tpl = Template('{% load i18n %}{% blocktrans context "female" %}It is 100%{% endblocktrans %}')
+ block_tpl = Template('{% load i18n %}{% blocktranslate context "female" %}It is 100%{% endblocktranslate %}')
self.assertEqual(block_tpl.render(Context({})), 'Elle est de 100%')
def test_translates_with_string_that_look_like_fmt_spec_with_trans(self):
# tests "%s"
expected = ('On dirait un spec str fmt %s mais ne devrait pas être interprété comme plus disponible')
trans_tpl = Template(
- '{% load i18n %}{% trans "Looks like a str fmt spec %s but '
+ '{% load i18n %}{% translate "Looks like a str fmt spec %s but '
'should not be interpreted as such" %}'
)
self.assertEqual(trans_tpl.render(Context({})), expected)
block_tpl = Template(
- '{% load i18n %}{% blocktrans %}Looks like a str fmt spec %s but '
- 'should not be interpreted as such{% endblocktrans %}'
+ '{% load i18n %}{% blocktranslate %}Looks like a str fmt spec %s but '
+ 'should not be interpreted as such{% endblocktranslate %}'
)
self.assertEqual(block_tpl.render(Context({})), expected)
# tests "% o"
expected = ('On dirait un spec str fmt % o mais ne devrait pas être interprété comme plus disponible')
trans_tpl = Template(
- '{% load i18n %}{% trans "Looks like a str fmt spec % o but should not be '
+ '{% load i18n %}{% translate "Looks like a str fmt spec % o but should not be '
'interpreted as such" %}'
)
self.assertEqual(trans_tpl.render(Context({})), expected)
block_tpl = Template(
- '{% load i18n %}{% blocktrans %}Looks like a str fmt spec % o but should not be '
- 'interpreted as such{% endblocktrans %}'
+ '{% load i18n %}{% blocktranslate %}Looks like a str fmt spec % o but should not be '
+ 'interpreted as such{% endblocktranslate %}'
)
self.assertEqual(block_tpl.render(Context({})), expected)
@@ -132,19 +132,19 @@ class RenderingTemplatesWithPercentSigns(FrenchTestCase):
expected = ('1 % signe pour cent, signes %% 2 pour cent, trois signes de pourcentage %%%')
trans_tpl = Template(
- '{% load i18n %}{% trans "1 percent sign %, 2 percent signs %%, '
+ '{% load i18n %}{% translate "1 percent sign %, 2 percent signs %%, '
'3 percent signs %%%" %}'
)
self.assertEqual(trans_tpl.render(Context({})), expected)
block_tpl = Template(
- '{% load i18n %}{% blocktrans %}1 percent sign %, 2 percent signs '
- '%%, 3 percent signs %%%{% endblocktrans %}'
+ '{% load i18n %}{% blocktranslate %}1 percent sign %, 2 percent signs '
+ '%%, 3 percent signs %%%{% endblocktranslate %}'
)
self.assertEqual(block_tpl.render(Context({})), expected)
block_tpl = Template(
- '{% load i18n %}{% blocktrans %}{{name}} says: 1 percent sign %, '
- '2 percent signs %%{% endblocktrans %}'
+ '{% load i18n %}{% blocktranslate %}{{name}} says: 1 percent sign %, '
+ '2 percent signs %%{% endblocktranslate %}'
)
self.assertEqual(
block_tpl.render(Context({"name": "Django"})),
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, 'α &amp; β')
@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, 'α &amp; β')
- @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 &amp; 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, 'α &amp; β')
@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, 'α &amp; β')
@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 %
diff --git a/tests/template_tests/syntax_tests/i18n/test_translate.py b/tests/template_tests/syntax_tests/i18n/test_translate.py
index 6011153a2d..55fdb92f7a 100644
--- a/tests/template_tests/syntax_tests/i18n/test_translate.py
+++ b/tests/template_tests/syntax_tests/i18n/test_translate.py
@@ -15,9 +15,9 @@ from .base import MultipleLocaleActivationTestCase, extended_locale_paths
def setup(templates, *args, **kwargs):
- trans_setup = base_setup(templates, *args, **kwargs)
- translate_setup = base_setup({
- name: template.replace('{% trans ', '{% translate ')
+ translate_setup = base_setup(templates, *args, **kwargs)
+ trans_setup = base_setup({
+ name: template.replace('{% translate ', '{% trans ')
for name, template in templates.items()
})
@@ -42,118 +42,118 @@ def setup(templates, *args, **kwargs):
class I18nTransTagTests(SimpleTestCase):
libraries = {'i18n': 'django.templatetags.i18n'}
- @setup({'i18n01': '{% load i18n %}{% trans \'xxxyyyxxx\' %}'})
+ @setup({'i18n01': '{% load i18n %}{% translate \'xxxyyyxxx\' %}'})
def test_i18n01(self):
"""simple translation of a string delimited by '."""
output = self.engine.render_to_string('i18n01')
self.assertEqual(output, 'xxxyyyxxx')
- @setup({'i18n02': '{% load i18n %}{% trans "xxxyyyxxx" %}'})
+ @setup({'i18n02': '{% load i18n %}{% translate "xxxyyyxxx" %}'})
def test_i18n02(self):
"""simple translation of a string delimited by "."""
output = self.engine.render_to_string('i18n02')
self.assertEqual(output, 'xxxyyyxxx')
- @setup({'i18n06': '{% load i18n %}{% trans "Page not found" %}'})
+ @setup({'i18n06': '{% load i18n %}{% translate "Page not found" %}'})
def test_i18n06(self):
"""simple translation of a string to German"""
with translation.override('de'):
output = self.engine.render_to_string('i18n06')
self.assertEqual(output, 'Seite nicht gefunden')
- @setup({'i18n09': '{% load i18n %}{% trans "Page not found" noop %}'})
+ @setup({'i18n09': '{% load i18n %}{% translate "Page not found" noop %}'})
def test_i18n09(self):
"""simple non-translation (only marking) of a string to German"""
with translation.override('de'):
output = self.engine.render_to_string('i18n09')
self.assertEqual(output, 'Page not found')
- @setup({'i18n20': '{% load i18n %}{% trans andrew %}'})
+ @setup({'i18n20': '{% load i18n %}{% translate andrew %}'})
def test_i18n20(self):
output = self.engine.render_to_string('i18n20', {'andrew': 'a & b'})
self.assertEqual(output, 'a &amp; b')
- @setup({'i18n22': '{% load i18n %}{% trans andrew %}'})
+ @setup({'i18n22': '{% load i18n %}{% translate andrew %}'})
def test_i18n22(self):
output = self.engine.render_to_string('i18n22', {'andrew': mark_safe('a & b')})
self.assertEqual(output, 'a & b')
- @setup({'i18n23': '{% load i18n %}{% trans "Page not found"|capfirst|slice:"6:" %}'})
+ @setup({'i18n23': '{% load i18n %}{% translate "Page not found"|capfirst|slice:"6:" %}'})
def test_i18n23(self):
- """Using filters with the {% trans %} tag (#5972)."""
+ """Using filters with the {% translate %} tag (#5972)."""
with translation.override('de'):
output = self.engine.render_to_string('i18n23')
self.assertEqual(output, 'nicht gefunden')
- @setup({'i18n24': '{% load i18n %}{% trans \'Page not found\'|upper %}'})
+ @setup({'i18n24': '{% load i18n %}{% translate \'Page not found\'|upper %}'})
def test_i18n24(self):
with translation.override('de'):
output = self.engine.render_to_string('i18n24')
self.assertEqual(output, 'SEITE NICHT GEFUNDEN')
- @setup({'i18n25': '{% load i18n %}{% trans somevar|upper %}'})
+ @setup({'i18n25': '{% load i18n %}{% translate somevar|upper %}'})
def test_i18n25(self):
with translation.override('de'):
output = self.engine.render_to_string('i18n25', {'somevar': 'Page not found'})
self.assertEqual(output, 'SEITE NICHT GEFUNDEN')
# trans tag with as var
- @setup({'i18n35': '{% load i18n %}{% trans "Page not found" as page_not_found %}{{ page_not_found }}'})
+ @setup({'i18n35': '{% load i18n %}{% translate "Page not found" as page_not_found %}{{ page_not_found }}'})
def test_i18n35(self):
with translation.override('de'):
output = self.engine.render_to_string('i18n35')
self.assertEqual(output, 'Seite nicht gefunden')
@setup({'i18n36': '{% load i18n %}'
- '{% trans "Page not found" noop as page_not_found %}{{ page_not_found }}'})
+ '{% translate "Page not found" noop as page_not_found %}{{ page_not_found }}'})
def test_i18n36(self):
with translation.override('de'):
output = self.engine.render_to_string('i18n36')
self.assertEqual(output, 'Page not found')
- @setup({'template': '{% load i18n %}{% trans %}A}'})
+ @setup({'template': '{% load i18n %}{% translate %}A}'})
def test_syntax_error_no_arguments(self, tag_name):
msg = "'{}' takes at least one argument".format(tag_name)
with self.assertRaisesMessage(TemplateSyntaxError, msg):
self.engine.render_to_string('template')
- @setup({'template': '{% load i18n %}{% trans "Yes" badoption %}'})
+ @setup({'template': '{% load i18n %}{% translate "Yes" badoption %}'})
def test_syntax_error_bad_option(self, tag_name):
msg = "Unknown argument for '{}' tag: 'badoption'".format(tag_name)
with self.assertRaisesMessage(TemplateSyntaxError, msg):
self.engine.render_to_string('template')
- @setup({'template': '{% load i18n %}{% trans "Yes" as %}'})
+ @setup({'template': '{% load i18n %}{% translate "Yes" as %}'})
def test_syntax_error_missing_assignment(self, tag_name):
msg = "No argument provided to the '{}' tag for the as option.".format(tag_name)
with self.assertRaisesMessage(TemplateSyntaxError, msg):
self.engine.render_to_string('template')
- @setup({'template': '{% load i18n %}{% trans "Yes" as var context %}'})
+ @setup({'template': '{% load i18n %}{% translate "Yes" as var context %}'})
def test_syntax_error_missing_context(self, tag_name):
msg = "No argument provided to the '{}' tag for the context option.".format(tag_name)
with self.assertRaisesMessage(TemplateSyntaxError, msg):
self.engine.render_to_string('template')
- @setup({'template': '{% load i18n %}{% trans "Yes" context as var %}'})
+ @setup({'template': '{% load i18n %}{% translate "Yes" context as var %}'})
def test_syntax_error_context_as(self, tag_name):
msg = "Invalid argument 'as' provided to the '{}' tag for the context option".format(tag_name)
with self.assertRaisesMessage(TemplateSyntaxError, msg):
self.engine.render_to_string('template')
- @setup({'template': '{% load i18n %}{% trans "Yes" context noop %}'})
+ @setup({'template': '{% load i18n %}{% translate "Yes" context noop %}'})
def test_syntax_error_context_noop(self, tag_name):
msg = "Invalid argument 'noop' provided to the '{}' tag for the context option".format(tag_name)
with self.assertRaisesMessage(TemplateSyntaxError, msg):
self.engine.render_to_string('template')
- @setup({'template': '{% load i18n %}{% trans "Yes" noop noop %}'})
+ @setup({'template': '{% load i18n %}{% translate "Yes" noop noop %}'})
def test_syntax_error_duplicate_option(self):
msg = "The 'noop' option was specified more than once."
with self.assertRaisesMessage(TemplateSyntaxError, msg):
self.engine.render_to_string('template')
- @setup({'template': '{% load i18n %}{% trans "%s" %}'})
+ @setup({'template': '{% load i18n %}{% translate "%s" %}'})
def test_trans_tag_using_a_string_that_looks_like_str_fmt(self):
output = self.engine.render_to_string('template')
self.assertEqual(output, '%s')
@@ -165,51 +165,51 @@ class TranslationTransTagTests(SimpleTestCase):
def get_template(self, template_string):
return Template(
template_string.replace(
- '{{% trans ',
+ '{{% translate ',
'{{% {}'.format(self.tag_name)
)
)
@override_settings(LOCALE_PATHS=extended_locale_paths)
def test_template_tags_pgettext(self):
- """{% trans %} takes message contexts into account (#14806)."""
+ """{% translate %} 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 %}{% trans "May" context "nonexistent" %}')
+ t = self.get_template('{% load i18n %}{% translate "May" context "nonexistent" %}')
rendered = t.render(Context())
self.assertEqual(rendered, 'May')
# Existing context... using a literal
- t = self.get_template('{% load i18n %}{% trans "May" context "month name" %}')
+ t = self.get_template('{% load i18n %}{% translate "May" context "month name" %}')
rendered = t.render(Context())
self.assertEqual(rendered, 'Mai')
- t = self.get_template('{% load i18n %}{% trans "May" context "verb" %}')
+ t = self.get_template('{% load i18n %}{% translate "May" context "verb" %}')
rendered = t.render(Context())
self.assertEqual(rendered, 'Kann')
# Using a variable
- t = self.get_template('{% load i18n %}{% trans "May" context message_context %}')
+ t = self.get_template('{% load i18n %}{% translate "May" context message_context %}')
rendered = t.render(Context({'message_context': 'month name'}))
self.assertEqual(rendered, 'Mai')
- t = self.get_template('{% load i18n %}{% trans "May" context message_context %}')
+ t = self.get_template('{% load i18n %}{% translate "May" context message_context %}')
rendered = t.render(Context({'message_context': 'verb'}))
self.assertEqual(rendered, 'Kann')
# Using a filter
- t = self.get_template('{% load i18n %}{% trans "May" context message_context|lower %}')
+ t = self.get_template('{% load i18n %}{% translate "May" context message_context|lower %}')
rendered = t.render(Context({'message_context': 'MONTH NAME'}))
self.assertEqual(rendered, 'Mai')
- t = self.get_template('{% load i18n %}{% trans "May" context message_context|lower %}')
+ t = self.get_template('{% load i18n %}{% translate "May" context message_context|lower %}')
rendered = t.render(Context({'message_context': 'VERB'}))
self.assertEqual(rendered, 'Kann')
# Using 'as'
- t = self.get_template('{% load i18n %}{% trans "May" context "month name" as var %}Value: {{ var }}')
+ t = self.get_template('{% load i18n %}{% translate "May" context "month name" as var %}Value: {{ var }}')
rendered = t.render(Context())
self.assertEqual(rendered, 'Value: Mai')
- t = self.get_template('{% load i18n %}{% trans "May" as var context "verb" %}Value: {{ var }}')
+ t = self.get_template('{% load i18n %}{% translate "May" as var context "verb" %}Value: {{ var }}')
rendered = t.render(Context())
self.assertEqual(rendered, 'Value: Kann')
@@ -224,7 +224,7 @@ class MultipleLocaleActivationTransTagTests(MultipleLocaleActivationTestCase):
def get_template(self, template_string):
return Template(
template_string.replace(
- '{{% trans ',
+ '{{% translate ',
'{{% {}'.format(self.tag_name)
)
)
@@ -236,25 +236,25 @@ class MultipleLocaleActivationTransTagTests(MultipleLocaleActivationTestCase):
"""
with translation.override('fr'):
self.assertEqual(
- self.get_template("{% load i18n %}{% trans 'Yes' %}").render(Context({})),
+ self.get_template("{% load i18n %}{% translate 'Yes' %}").render(Context({})),
'Oui'
)
def test_multiple_locale_trans(self):
with translation.override('de'):
- t = self.get_template("{% load i18n %}{% trans 'No' %}")
+ t = self.get_template("{% load i18n %}{% translate 'No' %}")
with translation.override(self._old_language), translation.override('nl'):
self.assertEqual(t.render(Context({})), 'Nee')
def test_multiple_locale_deactivate_trans(self):
with translation.override('de', deactivate=True):
- t = self.get_template("{% load i18n %}{% trans 'No' %}")
+ t = self.get_template("{% load i18n %}{% translate 'No' %}")
with translation.override('nl'):
self.assertEqual(t.render(Context({})), 'Nee')
def test_multiple_locale_direct_switch_trans(self):
with translation.override('de'):
- t = self.get_template("{% load i18n %}{% trans 'No' %}")
+ t = self.get_template("{% load i18n %}{% translate 'No' %}")
with translation.override('nl'):
self.assertEqual(t.render(Context({})), 'Nee')
diff --git a/tests/template_tests/syntax_tests/test_invalid_string.py b/tests/template_tests/syntax_tests/test_invalid_string.py
index 18520aa7bf..b05abcfdf3 100644
--- a/tests/template_tests/syntax_tests/test_invalid_string.py
+++ b/tests/template_tests/syntax_tests/test_invalid_string.py
@@ -53,7 +53,7 @@ class InvalidStringTests(SimpleTestCase):
else:
self.assertEqual(output, '')
- @setup({'invalidstr07': '{% load i18n %}{% blocktrans %}{{ var }}{% endblocktrans %}'})
+ @setup({'invalidstr07': '{% load i18n %}{% blocktranslate %}{{ var }}{% endblocktranslate %}'})
def test_invalidstr07(self):
output = self.engine.render_to_string('invalidstr07')
if self.engine.string_if_invalid: