#30718: blocktrans is crashing when using percent signs when no variables were
supplied
-------------------------------------+-------------------------------------
Reporter: NyanKiyoshi | Owner: nobody
Type: Bug | Status: new
Component: | Version: 2.2
Internationalization |
Severity: Normal | Resolution:
Keywords: i18n blocktrans | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by NyanKiyoshi:
Old description:
> 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:
> [https://github.com/django/django/blob/1e429df748867097451bf0b45d1080ae6828d921/django/templatetags/i18n.py#L161
> 1e429df7488/django/templatetags/i18n.py#L161]
>
> The PO compiler doesn't check the validity of the provided translation as
> the flag [https://www.gnu.org/software/gettext/manual/html_node/PO-
> Files.html python-format] flag is not generated in the PO file is not
> set.
>
> 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.
New description:
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:
[https://github.com/django/django/blob/1e429df748867097451bf0b45d1080ae6828d921/django/templatetags/i18n.py#L161
1e429df7488/django/templatetags/i18n.py#L161]
The PO compiler doesn't check the validity of the provided translation as
the flag [https://www.gnu.org/software/gettext/manual/html_node/PO-
Files.html 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.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/30718#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/069.ddca4aea6f860a3e7ccaeff2fccaf89a%40djangoproject.com.