Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Babel plugin drops many translator comments #225

Closed
sqlalchemy-bot opened this issue Dec 23, 2013 · 4 comments
Closed

Babel plugin drops many translator comments #225

sqlalchemy-bot opened this issue Dec 23, 2013 · 4 comments

Comments

@sqlalchemy-bot
Copy link

@sqlalchemy-bot sqlalchemy-bot commented Dec 23, 2013

Migrated issue, originally created by Anonymous

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)

@sqlalchemy-bot
Copy link
Author

@sqlalchemy-bot sqlalchemy-bot commented Dec 23, 2013

Michael Bayer (@zzzeek) wrote:

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!

@sqlalchemy-bot
Copy link
Author

@sqlalchemy-bot sqlalchemy-bot commented Dec 24, 2013

Anonymous wrote:

Pull Request: zzzeek/mako#6

@sqlalchemy-bot
Copy link
Author

@sqlalchemy-bot sqlalchemy-bot commented Dec 24, 2013

Michael Bayer (@zzzeek) wrote:

merged! 4d813ca. thanks! seems like we're due for a release, I have a few packages to be released and will try to get to this before new year's.

@sqlalchemy-bot
Copy link
Author

@sqlalchemy-bot sqlalchemy-bot commented Dec 24, 2013

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant