]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Fixed bug introduced in [92], bad use of `lstrip()`. Added a unittest to test multipl...
authorPedro Algarvio <pedro@algarvio.me>
Mon, 11 Jun 2007 23:29:45 +0000 (23:29 +0000)
committerPedro Algarvio <pedro@algarvio.me>
Mon, 11 Jun 2007 23:29:45 +0000 (23:29 +0000)
babel/messages/extract.py
babel/messages/tests/extract.py

index cf0ab6b0fca61c9c3e9fe74d713bb50219f79558..53b739ccb61c1ffdf41a654468c45f78194df4cf 100644 (file)
@@ -293,13 +293,23 @@ def extract_python(fileobj, keywords, comment_tags, options):
         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
index cbfef516824050640c7cb9b96407bf09f9c5053d..298e24fd8dd1814f451d7e3762b15ac500cbae93 100644 (file)
@@ -70,6 +70,23 @@ msg = _(u'Foo Bar')
         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))