'Update the catalog based on the given template catalog.
>>> from babel.messages import Catalog
>>> template = Catalog()
>>> template.add(\'green\', locations=[(\'main.py\', 99)])
>>> template.add(\'blue\', locations=[(\'main.py\', 100)])
>>> template.add((\'salad\', \'salads\'), locations=[(\'util.py\', 42)])
>>> catalog = Catalog(locale=\'de_DE\')
>>> catalog.add(\'blue\', u\'blau\', locations=[(\'main.py\', 98)])
>>> catalog.add(\'head\', u\'Kopf\', locations=[(\'util.py\', 33)])
>>> catalog.add((\'salad\', \'salads\'), (u\'Salat\', u\'Salate\'),
...             locations=[(\'util.py\', 38)])
>>> catalog.update(template)
>>> len(catalog)
3
>>> msg1 = catalog[\'green\']
>>> msg1.string
>>> msg1.locations
[(\'main.py\', 99)]
>>> msg2 = catalog[\'blue\']
>>> msg2.string
u\'blau\'
>>> msg2.locations
[(\'main.py\', 100)]
>>> msg3 = catalog[\'salad\']
>>> msg3.string
(u\'Salat\', u\'Salate\')
>>> msg3.locations
[(\'util.py\', 42)]
Messages that are in the catalog but not in the template are removed
from the main collection, but can still be accessed via the `obsolete`
member:
>>> \'head\' in catalog
False
>>> catalog.obsolete.values()
[<Message \'head\' (flags: [])>]
:param template: the reference catalog, usually read from a POT file
:param no_fuzzy_matching: whether to use fuzzy matching of message IDs'

def update(self, template, no_fuzzy_matching=False):

    messages = self._messages
    remaining = messages.copy()
    self._messages = odict()
    fuzzy_candidates = []
    if (not no_fuzzy_matching):
        fuzzy_candidates = [self._key_for(msgid) for msgid in messages if (msgid and messages[msgid].string)]
    fuzzy_matches = set()
    def _merge(message, oldkey, newkey):
        message = message.clone()
        fuzzy = False
        if (oldkey != newkey):
            fuzzy = True
            fuzzy_matches.add(oldkey)
            oldmsg = messages.get(oldkey)
            if isinstance(oldmsg.id, basestring):
                message.previous_id = [oldmsg.id]
            else:
                message.previous_id = list(oldmsg.id)
        else:
            oldmsg = remaining.pop(oldkey, None)
        message.string = oldmsg.string
        if isinstance(message.id, (list, tuple)):
            if (not isinstance(message.string, (list, tuple))):
                fuzzy = True
                message.string = tuple(([message.string] + ([u''] * (len(message.id) - 1))))
            elif (len(message.string) != self.num_plurals):
                fuzzy = True
                message.string = tuple(message.string[:len(oldmsg.string)])
        elif isinstance(message.string, (list, tuple)):
            fuzzy = True
            message.string = message.string[0]
        message.flags |= oldmsg.flags
        if fuzzy:
            message.flags |= set([u'fuzzy'])
        self[message.id] = message
    for message in template:
        if message.id:
            key = self._key_for(message.id)
            if (key in messages):
                _merge(message, key, key)
            else:
                if (no_fuzzy_matching is False):
                    matches = get_close_matches(key.lower().strip(), fuzzy_candidates, 1)
                    if matches:
                        _merge(message, matches[0], key)
                        continue
                self[message.id] = message
    self.obsolete = odict()
    for msgid in remaining:
        if (no_fuzzy_matching or (msgid not in fuzzy_matches)):
            self.obsolete[msgid] = remaining[msgid]
    self.creation_date = template.creation_date
