# HG changeset patch # User palgarvio # Date 1181604585 0 # Node ID ccb9da614597161d2d2e644f195e7ed2b2f6ce9a # Parent 5cff450b9ed57bfeb860a83e74b25cfc20fe0fa5 Fixed bug introduced in [92], bad use of `lstrip()`. Added a unittest to test multiple translator comment tags. diff --git a/babel/messages/extract.py b/babel/messages/extract.py --- 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 diff --git a/babel/messages/tests/extract.py b/babel/messages/tests/extract.py --- 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))