I am currently relying on django translations and I am curious to know if there is a better way to pick msgid for translations rather than the usual approach.
For instance:
In order to mark something for translation you have to do the following.
variable_name = _("Some Name")
and Django picks the msgid in the following way
msgid "Some Name"
msgstr "Some Name"
I currently would like to see if there is a way in which I can either pass a key to gettext
_("my string", "my_key")
or
An implementation in which the variable name becomes the msgid automatically when django picks up the variable.
msgid "variable_name"
msgstr "Some Name"
Any idea or suggestion would be really helpful.
The
msgidcan't be overwritten, it's a source string for translation. But you can use thedjango.utils.translation.pgettext()function to provide a contextual information:This will appear in the
.pofile as:In case your string needs pluralization, there is a
django.utils.translation.npgettext()function:This will appear in the
.pofile as: