# HG changeset patch # User jruigrok # Date 1266584936 0 # Node ID d2e9aaa7c91c9ed3b6afadeadbcc3ed84bee9df6 # Parent fa1625bcbe47615c4d8a0bad5f44b8b64e7feb22 Make sure to only strip on the first occurence of ]. Submitted by: Benoit Boissinot diff --git a/babel/messages/pofile.py b/babel/messages/pofile.py --- a/babel/messages/pofile.py +++ b/babel/messages/pofile.py @@ -187,7 +187,7 @@ 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]) diff --git a/babel/messages/tests/pofile.py b/babel/messages/tests/pofile.py --- a/babel/messages/tests/pofile.py +++ b/babel/messages/tests/pofile.py @@ -200,7 +200,18 @@ 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"