]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
pofile reader: Fix multi line msgctxt
authorMichael Birtwell <michael.birtwell@starleaf.com>
Wed, 12 Oct 2016 16:15:43 +0000 (17:15 +0100)
committerMichael Birtwell <michael.birtwell@starleaf.com>
Mon, 21 Nov 2016 14:32:49 +0000 (14:32 +0000)
babel/messages/pofile.py
tests/messages/test_pofile.py

index 2d1854b1c0a7c86db445f0200409e36e112abe5e..47db8a9f74c0a931730cf7dff3005fcef2f87ba5 100644 (file)
@@ -190,6 +190,7 @@ class PoFileParser(object):
             self.offset = lineno
 
         if keyword in ['msgid', 'msgid_plural']:
+            self.in_msgctxt = False
             self.in_msgid = True
             self.messages.append(_NormalizedString(arg))
 
@@ -201,7 +202,9 @@ class PoFileParser(object):
                 self.translations.append([int(idx), _NormalizedString(msg)])
             else:
                 self.translations.append([0, _NormalizedString(arg)])
+
         elif keyword == 'msgctxt':
+            self.in_msgctxt = True
             self.context = _NormalizedString(arg)
 
     def _process_string_continuation_line(self, line, lineno):
index cdb90f5e9fabb9cd728c64f8c523b90801cb1de8..64bf7148cfc19ea3c9d7afc2e48562d39602c26a 100644 (file)
@@ -287,6 +287,20 @@ msgstr "Bahr"
         self.assertEqual(message.context, "other")
         self.assertEqual(message.string, "Voh")
 
+    def test_multiline_context(self):
+        buf = StringIO('''
+msgctxt "a really long "
+"message context "
+"why?"
+msgid "mid"
+msgstr "mst"
+        ''')
+        catalog = pofile.read_po(buf)
+        self.assertEqual(1, len(catalog))
+        message = catalog.get('mid', context="a really long message context why?")
+        assert message is not None
+        self.assertEqual("a really long message context why?", message.context)
+
     def test_with_context_two(self):
         buf = BytesIO(b'''msgctxt "Menu"
 msgid "foo"