Opened 16 months ago

Last modified 5 months ago

#21963 assigned Bug

makemessages still ignores translations in templates with inline comment tags

Reported by: Ihor Kaharlichenko <madkinder@…> Owned by: dzhibas
Component: Internationalization Version: 1.6
Severity: Normal Keywords: makemessages, template, gettext, xgettext
Cc: madkinder@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

This bug is claimed to be fixed in #19552, though it's not.

Here's the test case:

Template:

{% load i18n %}
 
{# Translators: Abbreviated month name #}
{% trans "Jan" %}
 
{# Translators: Abbreviated month name #}{% trans "Feb" %}
 
{% comment %}Translators: Abbreviated month name{% endcomment %}{% trans "Mar" %}
 
{# Translators: Abbreviated month name #} {% trans "Apr" %}
 
{% comment %}Translators: Abbreviated month name{% endcomment %} {% trans "May" %}

{# Translators: Abbreviated month name #}
{% trans "Jun" %}

{# Translators: Abbreviated month name #}

{% trans "Jul" %}

{% comment %}Translators: Abbreviated month name{% endcomment %}

{% trans "Aug" %}

The extraction session:

$ ./manage.py version
1.6.1
$ ./manage.py makemessages -l ru -i venv
.../trans_real.py:585: TranslatorCommentWarning: The translator-targeted comment 'Translators: Abbreviated month name' (file app1/templates/i18n_test.html, line 6) was ignored, because it wasn't the last item on the line.
  warnings.warn(warn_msg, TranslatorCommentWarning)

.../trans_real.py:585: TranslatorCommentWarning: The translator-targeted comment 'Translators: Abbreviated month name' (file app1/templates/i18n_test.html, line 10) was ignored, because it wasn't the last item on the line.
  warnings.warn(warn_msg, TranslatorCommentWarning)

processing locale ru

Resulting po file:

#. Translators: Abbreviated month name
#: app1/templates/i18n_test.html:4
msgid "Jan"
msgstr ""

#: app1/templates/i18n_test.html:6
msgid "Feb"
msgstr ""

#. Translators: Abbreviated month name gettext(u'Mar')
#: app1/templates/i18n_test.html:10
msgid "Apr"
msgstr ""

#. Translators: Abbreviated month name  gettext(u'May')
#. Translators: Abbreviated month name
#: app1/templates/i18n_test.html:15
msgid "Jun"
msgstr ""

#. Translators: Abbreviated month name
#: app1/templates/i18n_test.html:19
msgid "Jul"
msgstr ""

#. Translators: Abbreviated month name
#: app1/templates/i18n_test.html:23
msgid "Aug"
msgstr ""

The problems:

  • translations for "Mar" and "May" were completely skipped
  • there was a warning for single-tag comments (for Feb and Apr), but not for block comments (for Mar and May), which is inconsistent
  • Apr and Jun got wrong comments

Change History (6)

comment:1 Changed 15 months ago by claudep

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 15 months ago by dzhibas

Hi,

fix should move all inline comments (with or without translators) at end of previous line rest will be covered by xgettext

here is partial fix for comments block in same line in front of trans which gives feeling of fix:
https://github.com/dzhibas/django/commit/c3369f5b1e9cc6f198d757f76924b956eeac13d8

same can be done for changes made for ticket #19552 and then translators comment will be (1) not ignored (2) in same line as translation string and will work with block {%comments%} & {#

Last edited 15 months ago by dzhibas (previous) (diff)

comment:3 Changed 15 months ago by dzhibas

if approach is good with coredev - i can finish patch, please let me know

comment:4 Changed 15 months ago by dzhibas

  • Owner changed from nobody to dzhibas
  • Status changed from new to assigned

comment:5 Changed 9 months ago by timgraham

  • Has patch set

Don't forget to check "Has patch" so the ticket appears in the review queue.

comment:6 Changed 5 months ago by timgraham

  • Patch needs improvement set
Note: See TracTickets for help on using tickets.
Back to Top