]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Make sure to only strip on the first occurence of ].
authorJeroen Ruigrok van der Werven <asmodai@in-nomine.org>
Fri, 19 Feb 2010 13:08:56 +0000 (13:08 +0000)
committerJeroen Ruigrok van der Werven <asmodai@in-nomine.org>
Fri, 19 Feb 2010 13:08:56 +0000 (13:08 +0000)
Submitted by: Benoit Boissinot

babel/messages/pofile.py
babel/messages/tests/pofile.py

index 1890294cec41ddecb5e008eb4a051231a2c5d40f..94bf122cef137ef962e3b7dc8474848aedee5c4c 100644 (file)
@@ -187,7 +187,7 @@ def read_po(fileobj, locale=None, domain=None, ignore_obsolete=False):
             in_msgstr[0] = True
             msg = line[6:].lstrip()
             if msg.startswith('['):
-                idx, msg = msg[1:].split(']')
+                idx, msg = msg[1:].split(']', 1)
                 translations.append([int(idx), msg.lstrip()])
             else:
                 translations.append([0, msg])
index 42580ecf02770855a1b5c1d7ae9b022f19706db2..f28648e642c3198255bec0cbe1f3084380db0590 100644 (file)
@@ -200,7 +200,18 @@ msgstr[1] "Vohs"''') # This is a bad po, ja_JP only uses msgstr[0]
         self.assertEqual(1, catalog.num_plurals)
         message = catalog['foo']
         self.assertEqual(1, len(message.string))
-        
+
+    def test_plural_with_square_brackets(self):
+        buf = StringIO(r'''msgid "foo"
+msgid_plural "foo"
+msgstr[0] "Voh [text]"
+msgstr[1] "Vohs [text]"''')
+        catalog = pofile.read_po(buf, locale='nb_NO')
+        self.assertEqual(1, len(catalog))
+        self.assertEqual(2, catalog.num_plurals)
+        message = catalog['foo']
+        self.assertEqual(2, len(message.string))
+
     def test_more_than_two_plural_forms(self):
         buf = StringIO(r'''msgid "foo"
 msgid_plural "foo"