pgettext(context, dictionary["key"]) records "key". Both arguments are variables, so the extractor should record no message.
What changed
extract_python counts [] and {} inside a translation call. String tokens and commas inside that depth are not message arguments. A nested call such as _(dictionary[_("inner")]) is still extracted. Adjacent literals (_("hello" "world")) still concatenate.
Scope
Python extractor only. JavaScript extraction is unchanged.
Tradeoffs
A string written inside a list or dict literal is no longer treated as the gettext argument. Those strings are data.
Blast Radius
Plain string arguments, implicit concatenation, and nested gettext calls keep the previous results. The new test covers the issue example, a subscript beside a real message, a dict, a list, a nested call, a normal pgettext, and implicit concatenation.
Verification
python -m pytest --noconftest tests/messages/test_extract_python.py — 34 passed.
python -m pytest --noconftest tests/messages/test_extract.py — 11 passed.
ruff check on the two edited files passed.
Did not run make import-cldr or the full tox matrix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
pgettext(context, dictionary["key"]) records "key". Both arguments are variables, so the extractor should record no message.
What changed
extract_python counts [] and {} inside a translation call. String tokens and commas inside that depth are not message arguments. A nested call such as _(dictionary[_("inner")]) is still extracted. Adjacent literals (_("hello" "world")) still concatenate.
Scope
Python extractor only. JavaScript extraction is unchanged.
Tradeoffs
A string written inside a list or dict literal is no longer treated as the gettext argument. Those strings are data.
Blast Radius
Plain string arguments, implicit concatenation, and nested gettext calls keep the previous results. The new test covers the issue example, a subscript beside a real message, a dict, a list, a nested call, a normal pgettext, and implicit concatenation.
Verification
python -m pytest --noconftest tests/messages/test_extract_python.py — 34 passed.
python -m pytest --noconftest tests/messages/test_extract.py — 11 passed.
ruff check on the two edited files passed.
Did not run make import-cldr or the full tox matrix.
Fixes #1335
Drafted with Cursor.