class Catalog(object):
Method | __iter__ |
Iterates through all the entries in the catalog, in the order they were added, yielding a Message object for every entry. |
Method | add |
Add or update the message with the specified ID. |
Method | check |
Run various validation checks on the translations in the catalog. |
Method | delete |
Delete the message with the specified ID and context. |
Method | get |
Return the message with the specified ID and context. |
Method | update |
Update the catalog based on the given template catalog. |
Class Variable | mime_headers |
Undocumented |
Instance Variable | header_comment |
Undocumented |
Instance Variable | language_team |
Name and email address of the language team. |
Instance Variable | last_translator |
Name and email address of the last translator. |
Method | __contains__ |
Return whether the catalog has a message with the specified ID. |
Method | __delitem__ |
Delete the message with the specified ID. |
Method | __getitem__ |
Return the message with the specified ID. |
Method | __init__ |
Initialize the catalog object. |
Method | __len__ |
The number of messages in the catalog. |
Method | __repr__ |
Undocumented |
Method | __setitem__ |
Add or update the message with the specified ID. |
Method | _get_header_comment |
Undocumented |
Method | _get_locale |
Undocumented |
Method | _get_locale_identifier |
Undocumented |
Method | _get_mime_headers |
Undocumented |
Method | _key_for |
The key for a message is just the singular ID even for pluralizable messages, but is a (msgid, msgctxt) tuple for context-specific messages. |
Method | _set_header_comment |
Undocumented |
Method | _set_locale |
Undocumented |
Method | _set_mime_headers |
Undocumented |
Class Variable | locale_identifier |
Undocumented |
Instance Variable | _header_comment |
Undocumented |
Instance Variable | _locale |
Undocumented |
Instance Variable | _locale_identifier |
Undocumented |
Instance Variable | _messages |
Undocumented |
Instance Variable | _num_plurals |
Undocumented |
Instance Variable | _plural_expr |
Undocumented |
Instance Variable | charset |
Undocumented |
Instance Variable | copyright_holder |
Undocumented |
Instance Variable | creation_date |
Undocumented |
Instance Variable | domain |
Undocumented |
Instance Variable | fuzzy |
Undocumented |
Instance Variable | locale |
Undocumented |
Instance Variable | msgid_bugs_address |
Undocumented |
Instance Variable | obsolete |
Undocumented |
Instance Variable | project |
Undocumented |
Instance Variable | revision_date |
Undocumented |
Instance Variable | version |
Undocumented |
Property | num_plurals |
The number of plurals used by the catalog or locale. |
Property | plural_expr |
The plural expression used by the catalog or locale. |
Property | plural_forms |
Return the plural forms declaration for the locale. |
Message
object for every entry.Returns | |
iterator | Undocumented |
Add or update the message with the specified ID.
>>> catalog = Catalog() >>> catalog.add(u'foo') <Message ...> >>> catalog[u'foo'] <Message u'foo' (flags: [])>
This method simply constructs a Message
object with the given
arguments and invokes __setitem__
with that object.
Parameters | |
id | the message ID, or a (singular, plural) tuple for pluralizable messages |
string | the translated message string, or a (singular, plural) tuple for pluralizable messages |
locations | a sequence of (filename, lineno) tuples |
flags | a set or sequence of flags |
auto_comments | a sequence of automatic comments |
user_comments | a sequence of user comments |
previous_id | the previous message ID, or a (singular, plural) tuple for pluralizable messages |
lineno | the line number on which the msgid line was found in the PO file, if any |
context | the message context |
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.
Returns | |
iterator | Undocumented |
Parameters | |
id | the message ID |
context | the message context, or None for no context |
Parameters | |
id | the message ID |
context | the message context, or None for no context |
Update the catalog based on the given template catalog.
>>> from babel.messages import Catalog >>> template = Catalog() >>> template.add('green', locations=[('main.py', 99)]) <Message ...> >>> template.add('blue', locations=[('main.py', 100)]) <Message ...> >>> template.add(('salad', 'salads'), locations=[('util.py', 42)]) <Message ...> >>> catalog = Catalog(locale='de_DE') >>> catalog.add('blue', u'blau', locations=[('main.py', 98)]) <Message ...> >>> catalog.add('head', u'Kopf', locations=[('util.py', 33)]) <Message ...> >>> catalog.add(('salad', 'salads'), (u'Salat', u'Salate'), ... locations=[('util.py', 38)]) <Message ...>
>>> 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 >>> list(catalog.obsolete.values()) [<Message 'head' (flags: [])>]
Parameters | |
template | the reference catalog, usually read from a POT file |
no_fuzzy_matching | whether to use fuzzy matching of message IDs |
update_header_comment | Undocumented |
keep_user_comments | Undocumented |
Parameters | |
locale | the locale identifier or Locale object, or None
if the catalog is not bound to a locale (which basically
means it's a template) |
domain | the message domain |
header_comment | the header comment as string, or None for the
default header |
project | the project's name |
version | the project's version |
copyright_holder | the copyright holder of the catalog |
msgid_bugs_address | the email address or URL to submit bug reports to |
creation_date | the date the catalog was created |
revision_date | the date the catalog was revised |
last_translator | the name and email of the last translator |
language_team | the name and email of the language team |
charset | the encoding to use in the output (defaults to utf-8) |
fuzzy | the fuzzy bit on the catalog header |
The number of messages in the catalog.
This does not include the special msgid "" entry.
Add or update the message with the specified ID.
>>> catalog = Catalog() >>> catalog[u'foo'] = Message(u'foo') >>> catalog[u'foo'] <Message u'foo' (flags: [])>
If a message with that ID is already in the catalog, it is updated to include the locations and flags of the new message.
>>> catalog = Catalog() >>> catalog[u'foo'] = Message(u'foo', locations=[('main.py', 1)]) >>> catalog[u'foo'].locations [('main.py', 1)] >>> catalog[u'foo'] = Message(u'foo', locations=[('utils.py', 5)]) >>> catalog[u'foo'].locations [('main.py', 1), ('utils.py', 5)]
Parameters | |
id | the message ID |
message | the Message object |
The number of plurals used by the catalog or locale.
>>> Catalog(locale='en').num_plurals 2 >>> Catalog(locale='ga').num_plurals 5