Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#21317 closed New feature (invalid)

Add translation to

Reported by: Toff Owned by: nobody
Component: contrib.messages Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


It will be great if you can add translation to DEFAULT_TAGS in,
so we can have a translation of 'info', 'warning', etc in templates by using {{message.tags}}

Attachments (1)

constants.diff (510 bytes) - added by Toff 4 years ago.

Download all attachments as: .zip

Change History (7)

Changed 4 years ago by Toff

Attachment: constants.diff added

comment:1 Changed 4 years ago by Toff

Summary: Add translation to constant.pyAdd translation to

comment:2 Changed 4 years ago by alasdair

message.tags is used for CSS - if you translated the DEFAULT_TAGS you would break the styling.

For example, in django/contrib/admin/templates/admin/

{% if messages %}
<ul class="messagelist">{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message|capfirst }}</li>
{% endfor %}</ul>
{% endif %}

I understand that you might want to display the translations of "info", "warning" etc to the user, but this would have to be a different attribute than message.tags.

Last edited 4 years ago by alasdair (previous) (diff)

comment:3 Changed 4 years ago by Claude Paroz

Resolution: invalid
Status: newclosed

IMHO, message tags are not meant as user-visible strings as their first role.
You can always mark those strings as translatable in your own project (i.e. ugettext_noop('debug'), etc.), then create your own template filter or tag to get translated tags.

comment:4 Changed 4 years ago by Aymeric Augustin

Claude, would you consider an API like message.get_tags_display to provide human-readable versions of the levels?

comment:5 Changed 4 years ago by Claude Paroz

I don't really see the use case of message.get_tags_display in the sense that there may be multiple space-separated tags returned. Maybe a message.get_level_display (which wouldn't consider extra_tags)? But once again, mixing tag and display roles with the same string doesn't seem very clean to me.
In any case, we would then need a use case common enough to justify it (considering that a custom template tag/filter can easily fill the "gap").

comment:6 Changed 4 years ago by Toff

You're right, i haven't seen this CSS breakdown.
message.tags is not intented for a direct text rendering.

I'll try an another way, like ugettext_noop as suggest claudep.

Thanks for your rapid answers and all your work.

Note: See TracTickets for help on using tickets.
Back to Top