]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Changed translator comments extraction behaviour in python source code. Match is...
authorPedro Algarvio <pedro@algarvio.me>
Mon, 11 Jun 2007 22:27:24 +0000 (22:27 +0000)
committerPedro Algarvio <pedro@algarvio.me>
Mon, 11 Jun 2007 22:27:24 +0000 (22:27 +0000)
babel/messages/extract.py
babel/messages/tests/extract.py

index 2c74529eeb0ee192a93115bb6bcb76fd2a05a542..cf0ab6b0fca61c9c3e9fe74d713bb50219f79558 100644 (file)
@@ -293,14 +293,13 @@ def extract_python(fileobj, keywords, comment_tags, options):
         if funcname and tok == OP and value == '(':
             in_args = True
         elif tok == COMMENT:
-            if in_translator_comments is True:
-                translator_comments.append(value[1:].strip())
-                continue
             for comment_tag in comment_tags:
-                if comment_tag in value:
+                value = value[1:].strip()
+                if value.startswith(comment_tag) or in_translator_comments:
                     if in_translator_comments is not True:
                         in_translator_comments = True
-                    translator_comments.append(value[1:].strip())
+                    comment = value.lstrip(comment_tag).strip()
+                    translator_comments.append(comment)
         elif funcname and in_args:
             if tok == OP and value == ')':
                 in_args = in_translator_comments = False
index 4dea8dbe979097bb1be574ce07daec2084f350f0..cbfef516824050640c7cb9b96407bf09f9c5053d 100644 (file)
@@ -30,9 +30,9 @@ class ExtractPythonTestCase(unittest.TestCase):
 # NOTE: A translation comment
 msg = _(u'Foo Bar')
 """)
-        messages = list(extract.extract_python(buf, ('_',), ['NOTE'], {}))
+        messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
         self.assertEqual('Foo Bar', messages[0][2])
-        self.assertEqual(['NOTE: A translation comment'], messages[0][3])
+        self.assertEqual(['A translation comment'], messages[0][3])
 
     def test_comment_tag_multiline(self):
         buf = StringIO("""
@@ -40,9 +40,9 @@ msg = _(u'Foo Bar')
 # with a second line
 msg = _(u'Foo Bar')
 """)
-        messages = list(extract.extract_python(buf, ('_',), ['NOTE'], {}))
+        messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
         self.assertEqual('Foo Bar', messages[0][2])
-        self.assertEqual(['NOTE: A translation comment', 'with a second line'],
+        self.assertEqual(['A translation comment', 'with a second line'],
                          messages[0][3])
         
     def test_translator_comments_with_previous_non_translator_comments(self):
@@ -53,12 +53,23 @@ msg = _(u'Foo Bar')
 # with a second line
 msg = _(u'Foo Bar')
 """)
-        messages = list(extract.extract_python(buf, ('_',), ['NOTE'], {}))
+        messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
         self.assertEqual('Foo Bar', messages[0][2])
-        self.assertEqual(['NOTE: A translation comment', 'with a second line'],
+        self.assertEqual(['A translation comment', 'with a second line'],
                          messages[0][3])
 
-
+    def test_comment_tags_not_on_start_of_comment(self):
+        buf = StringIO("""
+# This shouldn't be in the output
+# because it didn't start with a comment tag
+# do NOTE: this will no be a translation comment
+# NOTE: This one will be
+msg = _(u'Foo Bar')
+""")
+        messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
+        self.assertEqual('Foo Bar', messages[0][2])
+        self.assertEqual(['This one will be'], messages[0][3])
+        
 def suite():
     suite = unittest.TestSuite()
     suite.addTest(doctest.DocTestSuite(extract))