Edgewall Software
Please note:

The documentation here is generated live, in a way that is neither comprehensive nor 100% correct. We strongly recommend using the HTML documentation included with the source tarballs instead.

babel.messages.catalog

Data structures for message catalogs.

Message

Representation of a single message in a catalog.

clone(self)

(Not documented)

check(self, catalog=None)

Run various validation checks on the message. Some validations are only performed if the catalog is provided. This method returns a sequence of TranslationError objects.

rtype:iterator
param catalog:A catalog instance that is passed to the checkers
see:Catalog.check for a way to perform checks for all messages in a catalog.

fuzzy(self)

(Not documented)

pluralizable(self)

(Not documented)

python_format(self)

(Not documented)

TranslationError

Exception thrown by translation checkers when invalid message translations are encountered.

Catalog

Representation of a message catalog.

num_plurals(self)

(Not documented)

plural_expr(self)

(Not documented)

plural_forms(self)

(Not documented)

add(self, id, string=None, locations=, flags=, auto_comments=, user_comments=, previous_id=, lineno=None, context=None)

Add or update the message with the specified ID.

>>> catalog = Catalog()
>>> catalog.add(u'foo')
>>> catalog[u'foo']
<Message u'foo' (flags: [])>

This method simply constructs a Message object with the given arguments and invokes __setitem__ with that object.

param id:the message ID, or a (singular, plural) tuple for pluralizable messages
param string:the translated message string, or a (singular, plural) tuple for pluralizable messages
param locations:
 a sequence of (filenname, lineno) tuples
param flags:a set or sequence of flags
param auto_comments:
 a sequence of automatic comments
param user_comments:
 a sequence of user comments
param previous_id:
 the previous message ID, or a (singular, plural) tuple for pluralizable messages
param lineno:the line number on which the msgid line was found in the PO file, if any
param context:the message context

check(self)

Run various validation checks on the translations in the catalog.

For every message which fails validation, this method yield a (message, errors) tuple, where message is the Message object and errors is a sequence of TranslationError objects.

rtype:iterator

get(self, id, context=None)

Return the message with the specified ID and context.

param id:the message ID
param context:the message context, or None for no context
return:the message with the specified ID, or None if no such message is in the catalog
rtype:Message

delete(self, id, context=None)

Delete the message with the specified ID and context.

param id:the message ID
param context:the message context, or None for no context

update(self, template, no_fuzzy_matching=False)

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


See ApiDocs, Documentation