David Jean Louis avatar David Jean Louis committed cd3997d

Allow comments starting with two '#' characters + unittest

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):


 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."
         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.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.