Opened 11 years ago

Last modified 7 years ago

#21963 assigned Bug

makemessages still ignores translations in templates with inline comment tags

Reported by: Ihor Kaharlichenko <madkinder@…> Owned by: Sergey Kolosov
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 (10)

comment:1 by Claude Paroz, 11 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Nikolajus Krauklis, 11 years ago

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 11 years ago by Nikolajus Krauklis (previous) (diff)

comment:3 by Nikolajus Krauklis, 11 years ago

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

comment:4 by Nikolajus Krauklis, 11 years ago

Owner: changed from nobody to Nikolajus Krauklis
Status: newassigned

comment:5 by Tim Graham, 10 years ago

Has patch: set

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

comment:6 by Tim Graham, 10 years ago

Patch needs improvement: set

comment:7 by Sergey Kolosov, 8 years ago

Owner: changed from Nikolajus Krauklis to Sergey Kolosov

Looking into this (at DUTH '16).

comment:8 by Sergey Kolosov, 8 years ago

Patch needs improvement: unset

comment:10 by Carlton Gibson, 7 years ago

Patch needs improvement: set

Current patch simply reverts a number of changes from #19552. Including adding warnings (i.e. it removes them again), which seems a loss.
It reverses the logic of a number of test cases, going against decisions made in #19552.

I've suggested on the PR that we try and reach a consensus on the mailing list on the correct behaviour for each type of case. From there a resolution (without just reverting the previous work) should be easier.

Last edited 7 years ago by Carlton Gibson (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top