Opened 12 years ago
Closed 12 years ago
#20383 closed New feature (wontfix)
Makemessages must deal with context translations for a limited set of contexts.
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Translations | Version: | 1.4 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hi everyone.
Django makemessages
works fine when you define categorically a context to be used as a string, like
translated_message = pgettext('my_context', 'Hello World!')
But it can not "guess" your context when it's a variable (fair enough - when you have a variable with infinite possible values), like:
translated_message = pgettext(my_context_var, 'Hello World!')
However, I am working in a project that we have a limited set of contexts (in a white-label software where each context is a brand).
Given it is a limited set of contexts I think Django can understand this and generate translation messages with each one of these contexts.
Use case example: I have basically 3 values for contexts (for instance: "AAA", "BBB" and "CCC").
Sometimes, I have to use things like
translated_message = pgettext(CURRENT_CONTEXT, 'Hello World!')
Would be great if when Django makemessages
find a variable as the context, it generated one message for each possible context, as follows:
msgctxt "AAA" msgid "Hello World!" msgstr "" msgctxt "BBB" msgid "Hello World!" msgstr "" msgctxt "CCC" msgid "Hello World!" msgstr ""
The list of possible context to be used could be configured in the settings file, as follows:
# settings.py TRANSLATION_CONTEXTS = ( 'AAA', 'BBB', 'CCC', )
Does anyone else think this is a good feature to be added? Any predicted backwards incompatibility?
Thanks for explaining your use case in details. Unfortunately, I think that this use case is not common enough to justify the added complexity it implies.
You could write your own version of the
makemessages
command, and do the needed pre-processing stuff inTranslatableFile.process
, a bit like it is done for non-py files withtemplatize
. Not trivial, but doable.