﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
37486	makemessages fails to extract context from multiline translation tags	Patel Namraa	Patel Namraa	"The `makemessages` command doesn't correctly extract contextual translations from multiline `{% translate %}` and `{% blocktranslate %}` template tags.

For example:

{{{
{% blocktranslate
    with name=user.name
    context ""greeting""
%}
    Hello {{ name }}
{% endblocktranslate %}
}}}

The template parser correctly recognizes the message context at runtime. However, the extraction logic in `django/utils/translation/template.py` doesn't recognize contexts spanning multiple lines because the regular expressions used for parsing translation tags don't match newline characters.

Consequently, `makemessages` may extract the message without its context, producing an incorrect gettext entry. This is inconsistent with the contextual translation lookup performed at runtime.

There is also a source-location issue. Newlines inside multiline template tags aren't preserved in the output generated by `templatize()`. As a result, subsequent messages can receive incorrect line numbers in generated `.po` files.

This can also affect the association of translator comments with extracted messages.

== Proposed fix ==

The regular expressions used for extracting translation contexts should support multiline tags.

Additionally, the original newlines inside template tags should be preserved during templatization so that gettext receives accurate source locations.

Regression tests should cover:

- Multiline `{% translate %}` tags with message contexts.
- Multiline `{% blocktranslate %}` tags with message contexts.
- Correct extraction of contextual message IDs.
- Preservation of source line numbers after multiline tags.

The issue can be reproduced using `templatize()` directly, and the proposed changes include regression tests covering the affected extraction behavior."	Bug	assigned	Internationalization	dev	Normal			Patel Namraa	Unreviewed	0	0	0	0	0	0
