Opened 8 years ago
Last modified 8 years ago
#27730 closed Cleanup/optimization
i18n: trans tag with "as" does not work across blocks — at Version 1
Reported by: | Peter Bittner | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 1.10 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
The trans ... as
tag as documented in topics / i18n / translation only works in an isolated fashion outside blocks or inside of blocks. In other words, it does not work across blocks when defined outside of them, i.e. "globally" in a template.
The following example doesn't work: -- the value of {{ title }}
will be empty.
{% extends 'base.html' %}{% load i18n %} {% trans "My Projects" as title %} {% block head_title %}{{ title }}{% endblock %} {% block content %} <h2>{{ title }}</h2> {% endblock %}
This behavior is not documented, and neither is this behavior intuitive.
The same behavior and/or lack of documentation is true for blocktrans asvar ...
.
Enhancement or Documentation Fix?
This issue should be clarified and either fixed in the documentation (if the observations are confirmed), or alternatively changed in the template tag's behavior (if feasible and sensible).
Which route should be taken? Please clarify.
See Also
- GitHub commit 839edce (comment) -- related changes to the documentation; original report/comment
- Related StackOverflow question -- {% trans “string” as my_translated_string %} is not rendering content in template