﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30081	Translation with context - makemessages doesn't recognize the context	אורי	nobody	"We are using Django for [https://github.com/speedy-net/speedy-net Speedy Net and Speedy Match] (currently Django 1.11.18, we can't upgrade to a newer version of Django because of one of our requirements, django-modeltranslation). I have a problem with translating strings with context. We use context mainly for translating strings differently depending on the user's gender, which translates differently in languages such as Hebrew, although the English strings are the same. For example, I have this code:

{{{#!python
raise ValidationError(pgettext_lazy(context=self.instance.get_gender(), message=""You can't change your username.""))
}}}

(you can see it on https://github.com/speedy-net/speedy-net/blob/staging/speedy/core/accounts/forms.py)

The problem is that `manage.py makemessages` doesn't recognize the context here. A workaround we found is to include this text manually in files we don't use at all, such as `__translations.py` or `__translations.html` (you can see them on https://github.com/speedy-net/speedy-net/blob/staging/speedy/core/base/__translations.py and https://github.com/speedy-net/speedy-net/blob/staging/speedy/core/templates/__translations.html respectively), and there we can include the same strings with context:

Either:

{{{#!python
pgettext_lazy(context=""female"", message=""You can't change your username."")
pgettext_lazy(context=""male"", message=""You can't change your username."")
pgettext_lazy(context=""other"", message=""You can't change your username."")
}}}

Or:

{{{#!python
{% trans ""You can't change your username."" context 'female' %}
{% trans ""You can't change your username."" context 'male' %}
{% trans ""You can't change your username."" context 'other' %}
}}}

But this is a lot of work and we have each string 4 times in our code (not including translations), and it's very difficult to maintain such a code. And as I said, these files are not used at all, they are only for `./make_all_messages.sh` to work properly. So my question is - is there a way to pass all the possible contexts as a list to `manage.py makemessages`? For example add another argument to `pgettext_lazy` or add a specific comment which will be read by `manage.py makemessages`? I checked and currently we use translation with context about 100 times in this project, and it would be a lot of work to generate all this code (100 * 3 times) just for `manage.py makemessages` to work.

By the way, the method `get_gender()` always returns one of these strings: ""female"", ""male"" or ""other"". There is also another method, `get_match_gender()`, which returns the same values.

Is it possible to define the context ""other"" as default, so if a different context (or none) is passed and there is no translation with the given context, ""other"" will be used?"	New feature	closed	Core (Management commands)	1.11	Normal	wontfix			Unreviewed	0	0	0	0	0	0
