i18n in Jinja + Django - Is it possible to put <span>. <b> and other tags inside {% trans %}
I'm using coffin to interface with Jinja2 for Django templating.
I've run into a situation where I need to translate this p开发者_Go百科iece of text which looks like this:
<a href= "#"> This is a test <b> text </b>.</a> The quick brown <span class="red"> fox </span>
so, i'm currently doing something like this to translate it
< a href= "#">{% trans %}This is a test{% endtrans %} < b> {% trans %}text{% endtrans %} < /b>. < /a> {% trans %}The quick brown{% endtrans %} < span class="red"> {% trans %}fox{% endtrans %} < /span>
I can tell there must be an easier way to translate text which have html tags within them. What is the best way to proceed?
is this a valid way to do it?
{% trans %}<a href= "#">This is a test <b> text </b>. </a> The quick brown <span class="red"> fox </span>{% endtrans %}
Thanks!
You can use HTML tags inside your .po file. This way, your translators will have the full context of your strings and they can adjust the tags to match the intended result.
While it is valid, it puts the burden of keeping valid HTML syntax on translators (not to mention being more volatile), so you should rather avoid doing this. AFAIR, you can do <a href="">{{ _('This is a test') }} <b>{{ _('text') }}</b> ...
in Jinja, if you want a syntax with less tag noise.
精彩评论