Commits

David Jean Louis committed cd3997d

Allow comments starting with two '#' characters + unittest

  • Participants
  • Parent commits fd085f3

Comments (0)

Files changed (3)

                 # we are on a flags line
                 self.process('FL', i)
 
-            elif tokens[0] == '#':
+            elif tokens[0] == '#' or tokens[0].startswith('##'):
                 if line == '#': line += ' '
                 # we are on a translator comment line
                 self.process('TC', i)
             self.current_entry = POEntry()
         if self.current_entry.tcomment != '':
             self.current_entry.tcomment += '\n'
-        self.current_entry.tcomment += self.current_token[2:]
+        tcomment = self.current_token.lstrip('#')
+        if tcomment.startswith(' '):
+            tcomment = tcomment[1:]
+        self.current_entry.tcomment += tcomment
         return True
 
     def handle_gc(self):

File tests/test_utf8.po

 msgid "Some msgid"
 msgstr ""
 
+## Some comment starting with two '#'
 #: db/models/manipulators.py:309
 #, python-format
 msgid "%(object)s with this %(type)s already exists for the given %(field)s."

File tests/tests.py

         self.assertNotEqual(po.metadata, {})
         self.assertEqual(po.metadata['Content-Type'], 'text/plain; charset=UTF-8')
 
+    def test_comment_starting_with_two_hashes(self):
+        po = polib.pofile('tests/test_utf8.po')
+        e = po.find("Some comment starting with two '#'", by='tcomment')
+        self.assertTrue(isinstance(e, polib.POEntry))
+
 class TestMoFile(unittest.TestCase):
     """
     Tests for MoFile class.