Issues

Issue #225 resolved

Babel plugin drops many translator comments

guest
created an issue

The Babel plugin is supposed to retain translator comments if they are on a line preceding a translated string. But the logic in the Babel plugin clears the collected translator comments when intervening nodes are encountered.

## This comment works just fine.
## Translators: days_early_for_beta should not be translated
${_("Enter days_early_for_beta:")}

## This one does not:
## Translators: days_early_for_beta should not be translated
<p>${_("Enter days_early_for_beta:")}</p>
## Because the "<p>" is a text node that clears the translator_comments list.

(Reported by Ned Batchelder, ned@nedbatchelder.com)

Comments (3)

  1. Mike Bayer repo owner

    hi Ned -

    first off let me apologize that we're still on this poorly maintained Trac instance, ultimately I'd like to move the issues here to Bitbucket but haven't had the opportunity to work much on exporting the trac issues.

    I've never worked with the Babel plugin (or Babel itself) and I'm not sure who wrote it, so I likely have to dig more into the tests and probably add new ones for these occasional issues that pop up. My totally random guess on this one looks like this, if you want to try it out:

    diff --git a/mako/ext/babelplugin.py b/mako/ext/babelplugin.py
    index ba244bd..a9bceb3 100644
    --- a/mako/ext/babelplugin.py
    +++ b/mako/ext/babelplugin.py
    @@ -93,8 +93,9 @@ def extract_nodes(nodes, keywords, comment_tags, options):
             elif isinstance(node, parsetree.Expression):
                 code = node.code.code
             else:
    -            translator_comments = []
    -            in_translator_comments = False
    +            if not isinstance(node, parsetree.Text):
    +                translator_comments = []
    +                in_translator_comments = False
                 continue
    
             # Comments don't apply unless they immediately preceed the message
    

    this is just the most naive fix, to exclude text nodes from clearing out the comment list.

    if you happen to know how this should be fixed, feel free to send a pullreq on either BB or github https://bitbucket.org/zzzeek/mako / https://github.com/zzzeek/mako. otherwise I'll have to find some time after the holiday to dig in. thanks for the bug report!

  2. Log in to comment