babel icon indicating copy to clipboard operation
babel copied to clipboard

pybabel extract: Extract pgettext with dynamic or default context (msgctxt)

Open alex-kowalczyk opened this issue 3 years ago • 0 comments

Overview Description

Contexts are widely used nowadays to differentiate genders in messages. For instance:

pgettext(gender, "{user_name} followed you").format(user_name)

pybabel extract ignores extraction of context when it is not a fixed in-place string but variable.

Steps to Reproduce

echo 'pgettext(gender, "{username} followed you")' > test.py
pybabel extract test.py -o /dev/stdout

Actual Results

#: test.py:1
msgid "{username} followed you"
msgstr ""

Expected Results

At minimum, a placeholder msgctxt "" should be included, to allow for easy replicating of context permutations by postprocessing script.

Ideally, pybabel extract should accept a new --default-contexts parameter and generate proper permutations of the message. This would match the same feature for front-end code in i18Next extraction: https://i18next-extract.netlify.app/#/configuration?id=defaultcontexts

pybabel extract test.py -o /dev/stdout --default-contexts=male,female

#: test.py:1
msgctxt "male"
msgid "{username} followed you"
msgstr ""

#: test.py:1
msgctxt "female"
msgid "{username} followed you"
msgstr ""

alex-kowalczyk avatar Aug 31 '22 07:08 alex-kowalczyk