# HG changeset patch # User cmlenz # Date 1181767834 0 # Node ID 14a3d766a701599a71f676a444a83725b8f2cead # Parent 0f641136aa6b051f1d0b3f344682b4020d31c315 Project name and version, and the charset are available via the `Catalog` object, and do not need to be passed to `write_pot()`. diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py --- a/babel/messages/frontend.py +++ b/babel/messages/frontend.py @@ -150,7 +150,11 @@ 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 @@ 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 @@ "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 @@ 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, diff --git a/babel/messages/pofile.py b/babel/messages/pofile.py --- a/babel/messages/pofile.py +++ b/babel/messages/pofile.py @@ -237,8 +237,7 @@ 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 @@ :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 @@ 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 @@ 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,