Question

Documentation of Django says Contextual markers are also supported by the trans and blocktrans template tags. but it not explained how to do it?

Can you help marking translation context since I have some words with several meanings.

In Python I can do in such way:

pgettext("month name", "May")
pgettext("verb", "May")

How to specify translation context in Django template?

{% blocktrans %}May{% endblocktrans %}
Était-ce utile?

La solution

It is explained at the very end of their specific paragraphs:

https://docs.djangoproject.com/en/dev/topics/i18n/translation/#trans-template-tag

{% trans %} also supports contextual markers using the context keyword:

{% trans "May" context "month name" %}

https://docs.djangoproject.com/en/dev/topics/i18n/translation/#blocktrans-template-tag

{% blocktrans %} also supports contextual markers using the context keyword:

{% blocktrans with name=user.username context "greeting" %}Hi {{ name }}{% endblocktrans %}

Autres conseils

{% blocktrans context "month name" %}May{% endblocktrans %}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top