]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes...
authorChristopher Lenz <cmlenz@gmail.com>
Tue, 17 Mar 2009 22:26:03 +0000 (22:26 +0000)
committerChristopher Lenz <cmlenz@gmail.com>
Tue, 17 Mar 2009 22:26:03 +0000 (22:26 +0000)
babel/messages/pofile.py
babel/messages/tests/pofile.py

index dd24735c48c9e491328b7607c7bdd05261e10add..1890294cec41ddecb5e008eb4a051231a2c5d40f 100644 (file)
@@ -192,6 +192,8 @@ def read_po(fileobj, locale=None, domain=None, ignore_obsolete=False):
             else:
                 translations.append([0, msg])
         elif line.startswith('msgctxt'):
+            if messages:
+                _add_message()
             in_msgid[0] = in_msgstr[0] = False
             context.append(line[7:].lstrip())
         elif line.startswith('"'):
index c4525fc6c2019b8c59abe0e63622ad79f000103c..42580ecf02770855a1b5c1d7ae9b022f19706db2 100644 (file)
@@ -169,6 +169,27 @@ msgstr "Bahr"
         assert out_buf.getvalue().strip() == buf.getvalue().strip(), \
                                                             out_buf.getvalue()
 
+    def test_with_context_two(self):
+        buf = StringIO(r'''msgctxt "Menu"
+msgid "foo"
+msgstr "Voh"
+
+msgctxt "Mannu"
+msgid "bar"
+msgstr "Bahr"
+''')
+        catalog = pofile.read_po(buf, ignore_obsolete=True)
+        self.assertEqual(2, len(catalog))
+        message = catalog.get('foo', context='Menu')
+        self.assertEqual('Menu', message.context)
+        message = catalog.get('bar', context='Mannu')
+        self.assertEqual('Mannu', message.context)
+        
+        # And verify it pass through write_po
+        out_buf = StringIO()
+        pofile.write_po(out_buf, catalog, omit_header=True)
+        assert out_buf.getvalue().strip() == buf.getvalue().strip(), out_buf.getvalue()
+
     def test_singlular_plural_form(self):
         buf = StringIO(r'''msgid "foo"
 msgid_plural "foo"