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
9 changes: 5 additions & 4 deletions babel/messages/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ def delete(self, id, context=None):
if key in self._messages:
del self._messages[key]

def update(self, template, no_fuzzy_matching=False):
def update(self, template, no_fuzzy_matching=False, update_header_comment=False):
"""Update the catalog based on the given template catalog.

>>> from babel.messages import Catalog
Expand Down Expand Up @@ -798,9 +798,10 @@ def _merge(message, oldkey, newkey):
if no_fuzzy_matching or msgid not in fuzzy_matches:
self.obsolete[msgid] = remaining[msgid]

# Allow the updated catalog's header to be rewritten based on the
# template's header
self.header_comment = template.header_comment
if update_header_comment:
# Allow the updated catalog's header to be rewritten based on the
# template's header
self.header_comment = template.header_comment

# Make updated catalog's POT-Creation-Date equal to the template
# used to update the catalog
Expand Down
10 changes: 8 additions & 2 deletions babel/messages/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,10 +545,12 @@ class update_catalog(Command):
'whether to omit obsolete messages from the output'),
('no-fuzzy-matching', 'N',
'do not use fuzzy matching'),
('update-header-comment', None,
'update target header comment'),
('previous', None,
'keep previous msgids of translated messages')
]
boolean_options = ['ignore_obsolete', 'no_fuzzy_matching', 'previous']
boolean_options = ['ignore_obsolete', 'no_fuzzy_matching', 'previous', 'update_header_comment']

def initialize_options(self):
self.domain = 'messages'
Expand All @@ -560,6 +562,7 @@ def initialize_options(self):
self.no_wrap = False
self.ignore_obsolete = False
self.no_fuzzy_matching = False
self.update_header_comment = False
self.previous = False

def finalize_options(self):
Expand Down Expand Up @@ -619,7 +622,10 @@ def run(self):
finally:
infile.close()

catalog.update(template, self.no_fuzzy_matching)
catalog.update(
template, self.no_fuzzy_matching,
update_header_comment=self.update_header_comment
)

tmpname = os.path.join(os.path.dirname(filename),
tempfile.gettempprefix() +
Expand Down
4 changes: 3 additions & 1 deletion tests/messages/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ def test_catalog_update():

cat.update(template)
assert len(cat) == 3
assert cat.header_comment == template.header_comment # Header comment also gets updated

msg1 = cat['green']
msg1.string
Expand All @@ -457,6 +456,9 @@ def test_catalog_update():
assert not 'head' in cat
assert list(cat.obsolete.values())[0].id == 'head'

cat.update(template, update_header_comment=True)
assert cat.header_comment == template.header_comment # Header comment also gets updated


def test_datetime_parsing():
val1 = catalog._parse_datetime_header('2006-06-28 23:24+0200')
Expand Down