changeset 94:655b03680d84

Fixed bug introduced in [92], bad use of `lstrip()`. Added a unittest to test multiple translator comment tags.
author palgarvio
date Mon, 11 Jun 2007 23:29:45 +0000
parents 30ed605cff51
children 979dc0d7bc5d
files babel/messages/extract.py babel/messages/tests/extract.py
diffstat 2 files changed, 30 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/babel/messages/extract.py
+++ b/babel/messages/extract.py
@@ -293,13 +293,23 @@
         if funcname and tok == OP and value == '(':
             in_args = True
         elif tok == COMMENT:
+            # Strip the comment token from the line
+            value = value[1:].strip()
+            if in_translator_comments is True:
+                # We're already inside a translator comment, continue appending
+                # XXX: Should we check if the programmer keeps adding the
+                # comment_tag for every comment line??? probably not!
+                translator_comments.append(value)
+                continue
+            # If execution reaches this point, let's see if comment line
+            # starts with one of the comment tags
             for comment_tag in comment_tags:
-                value = value[1:].strip()
-                if value.startswith(comment_tag) or in_translator_comments:
+                if value.startswith(comment_tag):
                     if in_translator_comments is not True:
                         in_translator_comments = True
-                    comment = value.lstrip(comment_tag).strip()
+                    comment = value[len(comment_tag):].strip()
                     translator_comments.append(comment)
+                    break
         elif funcname and in_args:
             if tok == OP and value == ')':
                 in_args = in_translator_comments = False
--- a/babel/messages/tests/extract.py
+++ b/babel/messages/tests/extract.py
@@ -70,6 +70,23 @@
         self.assertEqual('Foo Bar', messages[0][2])
         self.assertEqual(['This one will be'], messages[0][3])
         
+    def test_multiple_comment_tags(self):
+        buf = StringIO("""
+# NOTE1: A translation comment for tag1
+# with a second line
+msg = _(u'Foo Bar1')
+
+# NOTE2: A translation comment for tag2
+msg = _(u'Foo Bar2')
+""")
+        messages = list(extract.extract_python(buf, ('_',),
+                                               ['NOTE1:', 'NOTE2:'], {}))
+        self.assertEqual('Foo Bar1', messages[0][2])
+        self.assertEqual(['A translation comment for tag1',
+                          'with a second line'], messages[0][3])
+        self.assertEqual('Foo Bar2', messages[1][2])
+        self.assertEqual(['A translation comment for tag2'], messages[1][3])
+        
 def suite():
     suite = unittest.TestSuite()
     suite.addTest(doctest.DocTestSuite(extract))
Copyright (C) 2012-2017 Edgewall Software