You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow header_comment to be passed as an option to extract_message #82
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_comment as an option for extract_messages.
I am planning to prepare a patch, but wanted to open the issue first in case there was any early feedback.
@akx I may have had in mind to specify header_comment as an option in the [extract_messages] section of setup.cfg. Is that equivalent to specifying an option to pybabel extract?
I'm not extremely familiar with the Babel code in the Trac project, but nowhere do we instantiate a Catalog object directly, so I can't see how it's possible to set header_comment.
After the following patch, it would allow to be passed via header_comment of [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.
#
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 using sed and git to restore that, but it's kind of a waste...
Activity
sudheesh001 commentedon Feb 4, 2016
Both the links given hit a 404 page, I understand that the changes needed are in
class extract_messages(Command):but I already seein update catalog, should this be carried over to the
user_optionsinextract_messages?rjollos commentedon Feb 4, 2016
Updated the links.
akx commentedon Feb 8, 2016
@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.
or the sort. Did I understand correctly?
rjollos commentedon Feb 10, 2016
@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.jun66j5 commentedon Feb 10, 2016
After the following patch, it would allow to be passed via
header_commentof[extract_messages]section in setup.cfg.Example of setup.cfg:
akx commentedon Feb 12, 2016
@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? :)
lelit commentedon Feb 21, 2016
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 using
sedandgitto restore that, but it's kind of a waste...akx commentedon Feb 21, 2016
@lelit: That sounds sensible. Care to create another issue and describe the workflow you'd like regarding all this?
allow header_comment to be passed as an option to extract_message
Allow header_comment to be passed as an option to extract_message
Allow header_comment to be passed as an option to extract_message
allow header_comment to be passed as an option to extract_message (#720)