# HG changeset patch # User cmlenz # Date 1212789993 0 # Node ID aa3a4c57511e295376914c676d956910a814f302 # Parent 5f67aa47609c22371d1e19922b19b5c1ff4eaa9b Fix message catalog compilation for locales with more than two plural forms. Closes #95. Many thanks to Victor Safronovich for the patch. diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py --- a/babel/messages/frontend.py +++ b/babel/messages/frontend.py @@ -107,9 +107,10 @@ if not self.input_file: if self.locale: - po_files.append(os.path.join(self.directory, self.locale, - 'LC_MESSAGES', - self.domain + '.po')) + po_files.append((self.locale, + os.path.join(self.directory, self.locale, + 'LC_MESSAGES', + self.domain + '.po'))) mo_files.append(os.path.join(self.directory, self.locale, 'LC_MESSAGES', self.domain + '.mo')) @@ -118,12 +119,12 @@ po_file = os.path.join(self.directory, locale, 'LC_MESSAGES', self.domain + '.po') if os.path.exists(po_file): - po_files.append(po_file) + po_files.append((locale, po_file)) mo_files.append(os.path.join(self.directory, locale, 'LC_MESSAGES', self.domain + '.mo')) else: - po_files.append(self.input_file) + po_files.append((self.locale, self.input_file)) if self.output_file: mo_files.append(self.output_file) else: @@ -134,11 +135,11 @@ if not po_files: raise DistutilsOptionError('no message catalogs found') - for idx, po_file in enumerate(po_files): + for idx, (locale, po_file) in enumerate(po_files): mo_file = mo_files[idx] infile = open(po_file, 'r') try: - catalog = read_po(infile) + catalog = read_po(infile, locale) finally: infile.close() @@ -698,9 +699,10 @@ parser.error('you must specify either the input file or the ' 'base directory') if options.locale: - po_files.append(os.path.join(options.directory, options.locale, - 'LC_MESSAGES', - options.domain + '.po')) + po_files.append((options.locale, + os.path.join(options.directory, + options.locale, 'LC_MESSAGES', + options.domain + '.po'))) mo_files.append(os.path.join(options.directory, options.locale, 'LC_MESSAGES', options.domain + '.mo')) @@ -709,12 +711,12 @@ po_file = os.path.join(options.directory, locale, 'LC_MESSAGES', options.domain + '.po') if os.path.exists(po_file): - po_files.append(po_file) + po_files.append((locale, po_file)) mo_files.append(os.path.join(options.directory, locale, 'LC_MESSAGES', options.domain + '.mo')) else: - po_files.append(options.input_file) + po_files.append((options.locale, options.input_file)) if options.output_file: mo_files.append(options.output_file) else: @@ -727,11 +729,11 @@ if not po_files: parser.error('no message catalogs found') - for idx, po_file in enumerate(po_files): + for idx, (locale, po_file) in enumerate(po_files): mo_file = mo_files[idx] infile = open(po_file, 'r') try: - catalog = read_po(infile) + catalog = read_po(infile, locale) finally: infile.close() diff --git a/babel/messages/tests/frontend.py b/babel/messages/tests/frontend.py --- a/babel/messages/tests/frontend.py +++ b/babel/messages/tests/frontend.py @@ -660,6 +660,22 @@ if os.path.isfile(mo_file): os.unlink(mo_file) + def test_compile_catalog_with_more_than_2_plural_forms(self): + po_file = os.path.join(self.datadir, 'project', 'i18n', 'ru_RU', + 'LC_MESSAGES', 'messages.po') + mo_file = po_file.replace('.po', '.mo') + try: + self.cli.run(sys.argv + ['compile', + '--locale', 'ru_RU', '--use-fuzzy', + '-d', os.path.join(self.datadir, 'project', 'i18n')]) + assert os.path.isfile(mo_file) + self.assertEqual("""\ +compiling catalog %r to %r +""" % (po_file, mo_file), sys.stderr.getvalue()) + finally: + if os.path.isfile(mo_file): + os.unlink(mo_file) + def suite(): suite = unittest.TestSuite()