changeset 333:a355a55a5705

Fix message catalog compilation for locales with more than two plural forms. Closes #95. Many thanks to Victor Safronovich for the patch.
author cmlenz
date Fri, 06 Jun 2008 22:06:33 +0000
parents a7dff175b14f
children 20030b8888a1
files babel/messages/frontend.py babel/messages/tests/frontend.py
diffstat 2 files changed, 32 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- 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()
 
--- 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()
Copyright (C) 2012-2017 Edgewall Software