Opened 11 years ago

Closed 11 years ago

#20383 closed New feature (wontfix)

Makemessages must deal with context translations for a limited set of contexts.

Reported by: Filipe Waitman <filwaitman@…> 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?

Change History (1)

comment:1 by Claude Paroz, 11 years ago

Resolution: wontfix
Status: newclosed

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 in TranslatableFile.process, a bit like it is done for non-py files with templatize. Not trivial, but doable.

Note: See TracTickets for help on using tickets.
Back to Top