class documentation

class Catalog: (source)

View In Hierarchy

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_identical 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_identifier Undocumented
Class Variable mime_headers 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 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.
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.
Method _force_text Undocumented
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
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
def __contains__(self, id: _MessageID) -> bool: (source)

Return whether the catalog has a message with the specified ID.

def __delitem__(self, id: _MessageID): (source)

Delete the message with the specified ID.

def __getitem__(self, id: _MessageID) -> Message: (source)

Return the message with the specified ID. :param id: the message ID

def __init__(self, locale: (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

def __iter__(self) -> Iterator[Message]: (source)

Iterates through all the entries in the catalog, in the order they were added, yielding a `Message` object for every entry. :rtype: ``iterator``

def __len__(self) -> int: (source)

The number of messages in the catalog. This does not include the special ``msgid ""`` entry.

def __repr__(self) -> str: (source)

Undocumented

def __setitem__(self, id: _MessageID, message: Message): (source)

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

def add(self, id: _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)``

def delete(self, id: _MessageID, context: str|None = None): (source)

Delete the message with the specified ID and context. :param id: the message ID :param context: the message context, or ``None`` for no context

def get(self, id: _MessageID, context: str|None = None) -> Message|None: (source)

Return the message with the specified ID and context. :param id: the message ID :param context: the message context, or ``None`` for no context

def is_identical(self, other: Catalog) -> bool: (source)

Checks if catalogs are identical, taking into account messages and headers.

def update(self, template: 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

locale_identifier = (source)

Undocumented

mime_headers = (source)

Undocumented

Undocumented

copyright_holder = (source)

Undocumented

creation_date = (source)

Undocumented

Undocumented

Undocumented

header_comment = (source)

Undocumented

language_team = (source)

Name and email address of the language team.

last_translator = (source)

Name and email address of the last translator.

Undocumented

msgid_bugs_address = (source)

Undocumented

Undocumented

Undocumented

revision_date = (source)

Undocumented

Undocumented

@property
num_plurals: int = (source)

The number of plurals used by the catalog or locale. >>> Catalog(locale='en').num_plurals 2 >>> Catalog(locale='ga').num_plurals 5 :type: `int`

@property
plural_expr: str = (source)

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`

@property
plural_forms: str = (source)

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`

def _force_text(self, s: str|bytes, encoding: str = 'utf-8', errors: str = 'strict') -> str: (source)

Undocumented

def _get_header_comment(self) -> str: (source)

Undocumented

def _get_locale(self) -> Locale|None: (source)

Undocumented

def _get_locale_identifier(self) -> str|None: (source)

Undocumented

def _get_mime_headers(self) -> list[tuple[str, str]]: (source)

Undocumented

def _key_for(self, id: _MessageID, context: str|None = None) -> tuple[str, str]|str: (source)

The key for a message is just the singular ID even for pluralizable messages, but is a ``(msgid, msgctxt)`` tuple for context-specific messages.

def _set_header_comment(self, string: str|None): (source)

Undocumented

def _set_locale(self, locale: (Locale|str)|None): (source)

Undocumented

def _set_mime_headers(self, headers: Iterable[tuple[str, str]]): (source)

Undocumented

_header_comment = (source)

Undocumented

Undocumented

_locale_identifier = (source)

Undocumented

_messages = (source)

Undocumented

_num_plurals = (source)

Undocumented

_plural_expr = (source)

Undocumented