Django translates templatetag template parameters

Is there a simple solution for marking the string parameters inclusion_tag (or the template as a whole) for translation? In this example, I want to mark the second parameter for translation:

 {% render_tile_section qs "Foo" %} 

Using include_tag like this obviously doesn't work:

 from django.utils.translation import ugettext_lazy as _ @register.inclusion_tag('content/includes/tile_section.html') def render_tile_section(qs, headline=''): return {'qs': qs, 'headline': u'%s' % _(headline) if headline else ''} 

My first idea was to subclass inclusion_tag and make it work as a trans tag for string parameters. But as far as I know, the Django makemessages team will only evaluate trans and blocktrans in templates, or do I have a way to extend it? Any other ideas?

+4
source share
1 answer

Functionality is already built into jango templatetags templates. Completely skipped this in the docs :

 {% some_special_tag _("Page not found") value|yesno:_("yes,no") %} 
+5
source

All Articles