#19552: makemessages ignores translations in templates with inline comment tags
-------------------------------------+-------------------------------------
     Reporter:  juneih@…             |      Owner:  nobody
         Type:  Bug                  |     Status:  new
    Component:  Core (Management     |    Version:  1.4
  commands)                          |   Keywords:  makemessages, template,
     Severity:  Normal               |  gettext, xgettext
 Triage Stage:  Unreviewed           |  Has patch:  0
Easy pickings:  0                    |      UI/UX:  0
-------------------------------------+-------------------------------------
 I'm using the management command makemessages to create the po-file for
 translations in my Django project. I'm having trouble with translations in
 templates being ignored when they contain in-line comments. Example:


 {{{

 {# Nice comment #} {%trans "Translate me" %}

 }}}

 The string 'Translate me' is not added to the po-file. I've traced the
 reason for this to the templatize method in trans_real.py. At the bottom
 of the method you'll find the following lines:

 When running the makemessages management command
 {{{
  elif t.token_type == TOKEN_COMMENT:
     out.write(' # %s' % t.contents)
 }}}

 It appears that the comment is not blanked out, but kept and passed on to
 xgettext. The input for xgettext with the previous example will be:

 {{{
 # nice comment gettext('Translate me')
 }}}

 Which means xgettext interprets the entire line as a comment. I'm not
 really sure why gettext would need the comment in the first place, but the
 fix for me has been to just add a new line after the string, like so:

 {{{
  elif t.token_type == TOKEN_COMMENT:
     out.write(' # %s\n' % t.contents)
 }}}

 Now the input for xgettext is:

 {{{
 # nice comment
 gettext('Translate me')
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/19552>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to