class Catalog: (source)
Representation of a message catalog.
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 | __iter__ |
Iterates through all the entries in the catalog, in the order they were added, yielding a `Message` object for every entry. |
Method | __len__ |
The number of messages in the catalog. |
Method | __repr__ |
Undocumented |
Method | __setitem__ |
Add or update the message with the specified ID. |
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 | is |
Checks if catalogs are identical, taking into account messages and headers. |
Method | update |
Update the catalog based on the given template catalog. |
Class Variable | locale |
Undocumented |
Class Variable | mime |
Undocumented |
Instance Variable | charset |
Undocumented |
Instance Variable | copyright |
Undocumented |
Instance Variable | creation |
Undocumented |
Instance Variable | domain |
Undocumented |
Instance Variable | fuzzy |
Undocumented |
Instance Variable | header |
Undocumented |
Instance Variable | language |
Name and email address of the language team. |
Instance Variable | last |
Name and email address of the last translator. |
Instance Variable | locale |
Undocumented |
Instance Variable | msgid |
Undocumented |
Instance Variable | obsolete |
Undocumented |
Instance Variable | project |
Undocumented |
Instance Variable | revision |
Undocumented |
Instance Variable | version |
Undocumented |
Property | num |
The number of plurals used by the catalog or locale. |
Property | plural |
The plural expression used by the catalog or locale. |
Property | plural |
Return the plural forms declaration for the locale. |
Method | _force |
Undocumented |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Method | _key |
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 |
Undocumented |
Method | _set |
Undocumented |
Method | _set |
Undocumented |
Instance Variable | _header |
Undocumented |
Instance Variable | _locale |
Undocumented |
Instance Variable | _locale |
Undocumented |
Instance Variable | _messages |
Undocumented |
Instance Variable | _num |
Undocumented |
Instance Variable | _plural |
Undocumented |
(str|Locale)|None
= None, domain: str|None
= None, header_comment: str|None
= DEFAULT_HEADER, project: str|None
= None, version: str|None
= None, copyright_holder: str|None
= None, msgid_bugs_address: str|None
= None, creation_date: (datetime.datetime|str)|None
= None, revision_date: (((datetime.datetime|datetime.time)|float)|str)|None
= None, last_translator: str|None
= None, language_team: str|None
= None, charset: str|None
= None, fuzzy: bool
= True):
(source)
¶
Initialize the catalog object. :param 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) :param domain: the message domain :param header_comment: the header comment as string, or `None` for the default header :param project: the project's name :param version: the project's version :param copyright_holder: the copyright holder of the catalog :param msgid_bugs_address: the email address or URL to submit bug reports to :param creation_date: the date the catalog was created :param revision_date: the date the catalog was revised :param last_translator: the name and email of the last translator :param language_team: the name and email of the language team :param charset: the encoding to use in the output (defaults to utf-8) :param fuzzy: the fuzzy bit on the catalog header
Iterates through all the entries in the catalog, in the order they were added, yielding a `Message` object for every entry. :rtype: ``iterator``
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)] :param id: the message ID :param message: the `Message` object
_MessageID
, string: _MessageID|None
= None, locations: Iterable[ tuple[ str, int]]
= (), flags: Iterable[ str]
= (), auto_comments: Iterable[ str]
= (), user_comments: Iterable[ str]
= (), previous_id: _MessageID
= (), lineno: int|None
= None, context: str|None
= None) -> Message
:
(source)
¶
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. :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 ``(filename, 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
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: ``generator`` of ``(message, errors)``
Delete 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 and context. :param id: the message ID :param context: the message context, or ``None`` for no context
Catalog
, no_fuzzy_matching: bool
= False, update_header_comment: bool
= False, keep_user_comments: bool
= True):
(source)
¶
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: [])>] :param template: the reference catalog, usually read from a POT file :param no_fuzzy_matching: whether to use fuzzy matching of message IDs
The number of plurals used by the catalog or locale. >>> Catalog(locale='en').num_plurals 2 >>> Catalog(locale='ga').num_plurals 5 :type: `int`
The plural expression used by the catalog or locale. >>> Catalog(locale='en').plural_expr '(n != 1)' >>> Catalog(locale='ga').plural_expr '(n==1 ? 0 : n==2 ? 1 : n>=3 && n<=6 ? 2 : n>=7 && n<=10 ? 3 : 4)' >>> Catalog(locale='ding').plural_expr # unknown locale '(n != 1)' :type: `str`
Return the plural forms declaration for the locale. >>> Catalog(locale='en').plural_forms 'nplurals=2; plural=(n != 1);' >>> Catalog(locale='pt_BR').plural_forms 'nplurals=2; plural=(n > 1);' :type: `str`
str|bytes
, encoding: str
= 'utf-8', errors: str
= 'strict') -> str
:
(source)
¶
Undocumented