Opened 3 years ago

Last modified 4 weeks 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: no
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 (8)

comment:1 Changed 3 years ago by Claude Paroz

Triage Stage: UnreviewedAccepted

comment:2 Changed 3 years ago by Nikolajus Krauklis

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/8df7eaadce8167d05feb83e9f7d5333e760fcac1

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%} & {#

Version 1, edited 3 years ago by Nikolajus Krauklis (previous) (next) (diff)

comment:3 Changed 3 years ago by Nikolajus Krauklis

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

comment:4 Changed 3 years ago by Nikolajus Krauklis

Owner: changed from nobody to Nikolajus Krauklis
Status: newassigned

comment:5 Changed 2 years ago by Tim Graham

Has patch: set

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

comment:6 Changed 2 years ago by Tim Graham

Patch needs improvement: set

comment:7 Changed 4 weeks ago by Sergey Kolosov

Owner: changed from Nikolajus Krauklis to Sergey Kolosov

Looking into this (at DUTH '16).

comment:8 Changed 4 weeks ago by Sergey Kolosov

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