]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Project name and version, and the charset are available via the `Catalog` object...
authorChristopher Lenz <cmlenz@gmail.com>
Wed, 13 Jun 2007 20:50:34 +0000 (20:50 +0000)
committerChristopher Lenz <cmlenz@gmail.com>
Wed, 13 Jun 2007 20:50:34 +0000 (20:50 +0000)
babel/messages/frontend.py
babel/messages/pofile.py

index d2f050df995960bf98fda8c4005970b27f6009a7..7a6460c0b6dc649f75be4a6c8c7f913887b42c2f 100644 (file)
@@ -150,7 +150,11 @@ class extract_messages(Command):
         mappings = self._get_mappings()
         outfile = open(self.output_file, 'w')
         try:
-            catalog = Catalog(msgid_bugs_address=self.msgid_bugs_address)
+            catalog = Catalog(project=self.distribution.get_name(),
+                              version=self.distribution.get_version(),
+                              msgid_bugs_address=self.msgid_bugs_address,
+                              charset=self.charset)
+
             for dirname, (method_map, options_map) in mappings.items():
                 def callback(filename, method, options):
                     if method == 'ignore':
@@ -173,12 +177,12 @@ class extract_messages(Command):
                                 comments=comments)
 
             log.info('writing PO template file to %s' % self.output_file)
-            write_pot(outfile, catalog, project=self.distribution.get_name(),
-                     version=self.distribution.get_version(), width=self.width,
-                     charset=self.charset, no_location=self.no_location,
-                     omit_header=self.omit_header, sort_output=self.sort_output,
-                     sort_by_file=self.sort_by_file,
-                     copyright_holder=self.copyright_holder)
+            write_pot(outfile, catalog, width=self.width,
+                      no_location=self.no_location,
+                      omit_header=self.omit_header,
+                      sort_output=self.sort_output,
+                      sort_by_file=self.sort_by_file,
+                      copyright_holder=self.copyright_holder)
         finally:
             outfile.close()
 
@@ -475,7 +479,9 @@ class CommandLineInterface(object):
                          "exclusive")
 
         try:
-            catalog = Catalog(msgid_bugs_address=options.msgid_bugs_address)
+            catalog = Catalog(msgid_bugs_address=options.msgid_bugs_address,
+                              charset=options.charset)
+
             for dirname in args:
                 if not os.path.isdir(dirname):
                     parser.error('%r is not a directory' % dirname)
@@ -487,7 +493,7 @@ class CommandLineInterface(object):
                                 comments=comments)
 
             write_pot(outfile, catalog, width=options.width,
-                      charset=options.charset, no_location=options.no_location,
+                      no_location=options.no_location,
                       omit_header=options.omit_header,
                       sort_output=options.sort_output,
                       sort_by_file=options.sort_by_file,
index 135cd2660f66e0a017e38f77c699166fba97e8bf..594ed6b9ff104164763c1c8ea76e48559bf5c0c6 100644 (file)
@@ -237,8 +237,7 @@ def normalize(string, width=76):
         lines[-1] += '\n'
     return u'""\n' + u'\n'.join([escape(l) for l in lines])
 
-def write_pot(fileobj, catalog, project='PROJECT', version='VERSION', width=76,
-              charset='utf-8', no_location=False, omit_header=False,
+def write_pot(fileobj, catalog, width=76, no_location=False, omit_header=False,
               sort_output=False, sort_by_file=False, copyright_holder=None):
     r"""Write a ``gettext`` PO (portable object) template file for a given
     message catalog to the provided file-like object.
@@ -266,28 +265,22 @@ def write_pot(fileobj, catalog, project='PROJECT', version='VERSION', width=76,
     
     :param fileobj: the file-like object to write to
     :param catalog: the `Catalog` instance
-    :param project: the project name
-    :param version: the project version
     :param width: the maximum line width for the generated output; use `None`,
                   0, or a negative number to completely disable line wrapping
-    :param charset: the encoding
     :param no_location: do not emit a location comment for every message
     :param omit_header: do not include the ``msgid ""`` entry at the top of the
                         output
     :param copyright_holder: sets the copyright holder in the output
     """
     def _normalize(key):
-        return normalize(key, width=width).encode(charset, 'backslashreplace')
+        return normalize(key, width=width).encode(catalog.charset,
+                                                  'backslashreplace')
 
     def _write(text):
         if isinstance(text, unicode):
-            text = text.encode(charset)
+            text = text.encode(catalog.charset)
         fileobj.write(text)
 
-    catalog.project = project
-    catalog.version = version
-    catalog.charset = charset
-    
     if sort_output:
         messages = list(catalog)
         messages.sort(lambda x,y: cmp(x.id, y.id))
@@ -296,7 +289,7 @@ def write_pot(fileobj, catalog, project='PROJECT', version='VERSION', width=76,
         messages.sort(lambda x,y: cmp(x.locations, y.locations))
     else:
         messages = catalog
-        
+
     _copyright_holder = copyright_holder or 'ORGANIZATION'
 
     for message in messages:
@@ -305,10 +298,10 @@ def write_pot(fileobj, catalog, project='PROJECT', version='VERSION', width=76,
                 continue
             _write(POT_HEADER % {
                 'year': date.today().strftime('%Y'),
-                'project': project,
+                'project': catalog.project,
                 'copyright_holder': _copyright_holder,
             })
-            
+
         if message.comments:
             for comment in message.comments:
                 for line in textwrap.wrap(comment,