Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions babel/messages/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from babel import __version__ as VERSION
from babel import Locale, localedata
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
Expand Down Expand Up @@ -350,6 +350,8 @@ class extract_messages(Command):
('ignore-dirs=', None,
'Patterns for directories to ignore when scanning for messages. '
'Separate multiple patterns with spaces (default ".* ._")'),
('header-comment=', None,
'header comment for the catalog'),
]
boolean_options = [
'no-default-keywords', 'no-location', 'omit-header', 'no-wrap',
Expand Down Expand Up @@ -394,6 +396,7 @@ def initialize_options(self):
self.strip_comments = False
self.include_lineno = True
self.ignore_dirs = None
self.header_comment = None

def finalize_options(self):
if self.input_dirs:
Expand Down Expand Up @@ -478,7 +481,8 @@ def run(self):
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 or DEFAULT_HEADER))

for path, method_map, options_map in mappings:
def callback(filename, method, options):
Expand Down
9 changes: 9 additions & 0 deletions tests/messages/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1518,3 +1518,12 @@ def test_extract_ignore_dirs(monkeypatch, capsys, tmp_path, with_underscore_igno
# unless we opt in to ignore it again
assert ('ssshhh....' in pot_content) != with_underscore_ignore
assert ('_hidden_by_default' in pot_content) != with_underscore_ignore


def test_extract_header_comment(monkeypatch, tmp_path):
pot_file = tmp_path / 'temp.pot'
monkeypatch.chdir(project_dir)
cmdinst = configure_cli_command(f"extract . -o '{pot_file}' --header-comment 'Boing' ")
cmdinst.run()
pot_content = pot_file.read_text()
assert 'Boing' in pot_content