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 %}
{% extends variable %} uses the value of variable . If the variable evaluates to a string, Django will use that string as the name of the parent template. If the variable evaluates to a Template object, Django will use that object as the parent template.
A context processor has a simple interface: It's a Python function that takes one argument, an HttpRequest object, and returns a dictionary that gets added to the template context. Custom context processors can live anywhere in your code base.
The {% trans %} template tag The {% trans %} template tag allows you to mark a string, a constant, or variable content for translation. Internally, Django executes gettext() on the given text.
1. It will translate the string to the activated language if you defined a translation. See docs.djangoproject.com/en/4.0/topics/i18n/translation.
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 %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With