# HG changeset patch # User cmlenz # Date 1180520197 0 # Node ID 8d7b3077e6d184e2d9ba765aeeb697df73638a89 # Parent 04527ede83d0d2f7b94cc362b55445a23b4e7536 * The creation-date header in generated PO files now includes the timezone offset. * The distutils frontend pulls the project name and version from the distribution object. diff --git a/babel/catalog/frontend.py b/babel/catalog/frontend.py --- a/babel/catalog/frontend.py +++ b/babel/catalog/frontend.py @@ -56,7 +56,7 @@ 'do not include location comments with filename and line number'), ('omit-header', None, 'do not include msgid "" entry in header'), - ('output-file=', None, + ('output-file=', 'o', 'name of the output file'), ] boolean_options = ['no-location', 'omit-header'] @@ -88,8 +88,10 @@ for filename, lineno, funcname, message in extracted: messages.append((os.path.join(dirname, filename), lineno, funcname, message)) - write_po(outfile, messages, charset=self.charset, - no_location=self.no_location, omit_header=self.omit_header) + write_po(outfile, messages, project=self.distribution.get_name(), + version=self.distribution.get_version(), + charset=self.charset, no_location=self.no_location, + omit_header=self.omit_header) log.info('writing PO file to %s' % self.output_file) finally: outfile.close() diff --git a/babel/catalog/pofile.py b/babel/catalog/pofile.py --- a/babel/catalog/pofile.py +++ b/babel/catalog/pofile.py @@ -20,8 +20,9 @@ # TODO: line wrapping -from datetime import datetime +from datetime import date, datetime import re +import time from babel import __version__ as VERSION @@ -35,7 +36,7 @@ msgid "" msgstr "" "Project-Id-Version: %%(project)s %%(version)s\\n" -"POT-Creation-Date: %%(time)s\\n" +"POT-Creation-Date: %%(creation_date)s\\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n" "Last-Translator: FULL NAME \\n" "Language-Team: LANGUAGE \\n" @@ -123,8 +124,8 @@ if msg.startswith('['): pass # plural -def write_po(fileobj, messages, project=None, version=None, creation_date=None, - charset='utf-8', no_location=False, omit_header=False): +def write_po(fileobj, messages, project=None, version=None, charset='utf-8', + no_location=False, omit_header=False): r"""Write a ``gettext`` PO (portable object) file to the given file-like object. @@ -165,15 +166,12 @@ def _normalize(key): return normalize(key, charset=charset) - if creation_date is None: - creation_date = datetime.now() - if not omit_header: fileobj.write(POT_HEADER % { + 'project': project, + 'version': version, + 'creation_date': time.strftime('%Y-%m-%d %H:%M%z'), 'charset': charset, - 'time': creation_date.strftime('%Y-%m-%d %H:%M'), - 'project': project, - 'version': version }) locations = {}