Repository navigation
Allow header_comment to be passed as an option to extract_message #82
Description
Activity
Both the links given hit a 404 page, I understand that the changes needed are in
class extract_messages(Command):but I already see('update-header-comment', None, 'update target header comment'),in update catalog, should this be carried over to the
user_optionsinextract_messages?Both the links given hit a 404 page
Updated the links.
@sudheesh001 Update is another step of the message process (it roughly goes "extract", "update", "compile").
I think OP @rjollos would like to be able to simply set a header comment for new extractions, i.e.
pybabel extract --header-comment=blah ...
or the sort. Did I understand correctly?
@akx I may have had in mind to specify
header_commentas an option in the[extract_messages]section ofsetup.cfg. Is that equivalent to specifying an option topybabel extract?I'm not extremely familiar with the Babel code in the Trac project, but nowhere do we instantiate a
Catalogobject directly, so I can't see how it's possible to setheader_comment.After the following patch, it would allow to be passed via
header_commentof[extract_messages]section in setup.cfg.diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py index 9bb46bb..d6b1f53 100644 --- a/babel/messages/frontend.py +++ b/babel/messages/frontend.py @@ -24,7 +24,7 @@ from babel import __version__ as VERSION from babel import Locale, localedata from babel._compat import StringIO, string_types from babel.core import UnknownLocaleError -from babel.messages.catalog import Catalog +from babel.messages.catalog import Catalog, DEFAULT_HEADER from babel.messages.extract import DEFAULT_KEYWORDS, DEFAULT_MAPPING, check_and_call_extract_file, extract_from_dir from babel.messages.mofile import write_mo from babel.messages.pofile import read_po, write_po @@ -246,6 +246,8 @@ class extract_messages(Command): 'set project name in output'), ('version=', None, 'set project version in output'), + ('header-comment=', None, + 'set header comment for the catalog'), ('add-comments=', 'c', 'place comment block with TAG (or those preceding keyword lines) in ' 'output file. Separate multiple TAGs with commas(,)'), @@ -283,6 +285,7 @@ class extract_messages(Command): self.copyright_holder = None self.project = None self.version = None + self.header_comment = DEFAULT_HEADER self.add_comments = None self.strip_comments = False @@ -352,7 +355,8 @@ class extract_messages(Command): version=self.version, msgid_bugs_address=self.msgid_bugs_address, copyright_holder=self.copyright_holder, - charset=self.charset) + charset=self.charset, + header_comment=self.header_comment) for path, (method_map, options_map) in mappings.items(): def callback(filename, method, options):
Example of setup.cfg:
[extract_messages] add_comments = TRANSLATOR: copyright_holder = .... msgid_bugs_address = msgid@example.com output_file = foobar/locale/messages.pot header_comment = # Translations template for PROJECT. # Copyright (C) YEAR ORGANIZATION # This file is distributed under the same license as the PROJECT project. # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. #@jun66j5 That patch looks good! (And would allow
--header-comment=as a side effect.)Care to make a PR out of it, with a test case included? :)
I know it complicates the thing, but but would be nice to have a way to preserve previous bits of information. Currently the update process rewrites the whole header, in particular the last line with "FIRST AUTHOR...", effectively discarding both the original translator and the year.
i'm going to use a brute force fix usingsedandgitto restore that, but it's kind of a waste...@lelit: That sounds sensible. Care to create another issue and describe the workflow you'd like regarding all this?
- added a commit that references this issue
on Jul 16, 2020 - added 2 commits that reference this issue
on Apr 11, 2022 - added a commit that references this issue
on Apr 12, 2022
In Trac and Apache Bloodhound we utilize babel.extract_messages. For Apache Bloodhound, we'd like to be able to specify the header_comment parameter when creating the Catalog. We would like to add
header_commentas an option forextract_messages.I am planning to prepare a patch, but wanted to open the issue first in case there was any early feedback.