1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #19552 -- Enhanced makemessages handling of `{# #}`-style template comments.

They are simply ignored now. This allows for a more correct behavior when
they are placed before translatable constructs on the same line.

Previously, the latter were wrongly ignored because the former were
preserved when converting template code to the internal Python-syntax
form later fed to xgettext but Python has no ``/* ... */``-style
comments.

Also, special comments directed to translators are now only taken in
account when they are located at the end of a line. e.g.::

  {# Translators: ignored #}{% trans "Literal A" %}{# Translators: valid, associated with "Literal B" below #}
  {% trans "Literal B" %}

Behavior of ``{% comment %}...{% endcomment %}``tags remains unchanged.

Thanks juneih at redpill-linpro dot com for the report and Claude for
his work on the issue.
This commit is contained in:
Ramiro Morales
2013-01-20 15:07:10 -03:00
parent eb9430fc4b
commit 47ddd6a408
7 changed files with 200 additions and 6 deletions

View File

@@ -47,6 +47,26 @@ Backwards incompatible changes in 1.6
should review it as ``type='text'`` widgets might be now output as
``type='email'`` or ``type='url'`` depending on their corresponding field type.
* Extraction of translatable literals from templates with the
:djadmin:`makemessages` command now correctly detects i18n constructs when
they are located after a ``{#`` / ``#}``-type comment on the same line. E.g.:
.. code-block:: html+django
{# A comment #}{% trans "This literal was incorrectly ignored. Not anymore" %}
* (Related to the above item.) Validation of the placement of
:ref:`translator-comments-in-templates` specified using ``{#`` / ``#}`` is now
stricter. All translator comments not located at the end of their respective
lines in a template are ignored and a warning is generated by
:djadmin:`makemessages` when it finds them. E.g.:
.. code-block:: html+django
{# Translators: This is ignored #}{% trans "Translate me" %}
{{ title }}{# Translators: Extracted and associated with 'Welcome' below #}
<h1>{% trans "Welcome" %}</h1>
.. warning::
In addition to the changes outlined in this section, be sure to review the