# HG changeset patch # User cmlenz # Date 1212789108 0 # Node ID a7dff175b14f08c50b3361fd65f34c779b34f70c # Parent 852cd3703113695186d59b04a31d35390ff8833c Fix for #97, compilation of message catalogs for locales with more than two plural forms where the translations were empty was failing. diff --git a/babel/messages/mofile.py b/babel/messages/mofile.py --- a/babel/messages/mofile.py +++ b/babel/messages/mofile.py @@ -81,7 +81,7 @@ msgstrs = [] for idx, string in enumerate(message.string): if not string: - msgstrs.append(message.id[idx]) + msgstrs.append(message.id[min(int(idx), 1)]) else: msgstrs.append(string) msgstr = '\x00'.join([ diff --git a/babel/messages/tests/mofile.py b/babel/messages/tests/mofile.py --- a/babel/messages/tests/mofile.py +++ b/babel/messages/tests/mofile.py @@ -47,6 +47,13 @@ self.assertEqual(u'Fuzzes', translations.ugettext('Fuzzes')) assert isinstance(translations.ugettext('Fuzzes'), unicode) + def test_more_plural_forms(self): + catalog2 = Catalog(locale='ru_RU') + catalog2.add(('Fuzz', 'Fuzzes'), ('', '', '')) + buf = StringIO() + mofile.write_mo(buf, catalog2) + + def suite(): suite = unittest.TestSuite() suite.addTest(doctest.DocTestSuite(mofile))