Opened 5 years ago
Closed 5 years ago
#30718 closed Bug (wontfix)
blocktrans is crashing when using percent signs when no variables were supplied.
Reported by: | Mikail | Owned by: | nobody |
---|---|---|---|
Component: | Internationalization | Version: | dev |
Severity: | Normal | Keywords: | i18n blocktrans |
Cc: | Claude Paroz | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
When using blocktrans
without supplying any variables and a translator puts a percent sign as a translation, a crash occurs.
For example, using this template snippet:
{% blocktrans context "Taxes" %} tax_rate * price {% endblocktrans %}
If one translates it to:
% imposto * preço
It will raise:
TypeError: %i format: a number is required, not dict
Where stack is:
File "django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "django/core/handlers/base.py", line 145, in _get_response response = self.process_exception_by_middleware(e, request) File "django/core/handlers/base.py", line 143, in _get_response response = response.render() File "django/template/response.py", line 106, in render self.content = self.rendered_content File "django/template/response.py", line 83, in rendered_content content = template.render(context, self._request) File "django/template/backends/django.py", line 61, in render return self.template.render(context) File "django/template/base.py", line 171, in render return self._render(context) File "django/template/base.py", line 163, in _render return self.nodelist.render(context) File "django/template/base.py", line 937, in render bit = node.render_annotated(context) File "django/template/base.py", line 904, in render_annotated return self.render(context) File "django/template/loader_tags.py", line 150, in render return compiled_parent._render(context) File "django/template/base.py", line 163, in _render return self.nodelist.render(context) File "django/template/base.py", line 937, in render bit = node.render_annotated(context) File "django/template/base.py", line 904, in render_annotated return self.render(context) File "django/template/loader_tags.py", line 150, in render return compiled_parent._render(context) File "django/template/base.py", line 163, in _render return self.nodelist.render(context) File "django/template/base.py", line 937, in render bit = node.render_annotated(context) File "django/template/base.py", line 904, in render_annotated return self.render(context) File "django/template/loader_tags.py", line 62, in render result = block.nodelist.render(context) File "django/template/base.py", line 937, in render bit = node.render_annotated(context) File "django/template/base.py", line 904, in render_annotated return self.render(context) File "django/templatetags/i18n.py", line 161, in render result = result % data
The crashing line being this one: 1e429df7488/django/templatetags/i18n.py#L161
The PO compiler doesn't check the validity of the provided translation as the flag python-format is not set in the PO file.
We should whether not try to format the string if there is no variable, or force the python-format
flag to be set to prevent translators from breaking the templates.
Change History (3)
comment:1 by , 5 years ago
Description: | modified (diff) |
---|
comment:2 by , 5 years ago
Cc: | added |
---|---|
Summary: | blocktrans is crashing when using percent signs when no variables were supplied → blocktrans is crashing when using percent signs when no variables were supplied. |
Version: | 2.2 → master |
comment:3 by , 5 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Marking as "wontfix" (at least for now).
Thanks for the report, it looks like an edge case. Setting
python-format
for all messages is not an option IMO, we also (probably) are not able to check message flags at this point. Double percent signs of course fix this issue:I don't think that there is much we can do here.
Claude, do you have any ideas?