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
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
'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'
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):
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() +
cat.update(template)
assert len(cat) == 3
- assert cat.header_comment == template.header_comment # Header comment also gets updated
msg1 = cat['green']
msg1.string
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')