Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Properties | List of all members
babel.messages.catalog.Catalog Class Reference

Public Member Functions

None __init__ (self, Locale|str|None locale=None, str|None domain=None, str|None header_comment=DEFAULT_HEADER, str|None project=None, str|None version=None, str|None copyright_holder=None, str|None msgid_bugs_address=None, datetime.datetime|str|None creation_date=None, datetime.datetime|datetime.time|float|str|None revision_date=None, str|None last_translator=None, str|None language_team=None, str|None charset=None, bool fuzzy=True)
 
int num_plurals (self)
 
str plural_expr (self)
 
str plural_forms (self)
 
bool __contains__ (self, _MessageID id)
 
int __len__ (self)
 
Iterator[Message__iter__ (self)
 
str __repr__ (self)
 
None __delitem__ (self, _MessageID id)
 
Message __getitem__ (self, _MessageID id)
 
None __setitem__ (self, _MessageID id, Message message)
 
Message add (self, _MessageID id, _MessageID|None string=None, Iterable[tuple[str, int]] locations=(), Iterable[str] flags=(), Iterable[str] auto_comments=(), Iterable[str] user_comments=(), _MessageID previous_id=(), int|None lineno=None, str|None context=None)
 
Iterable[tuple[Message, list[TranslationError]]] check (self)
 
Message|None get (self, _MessageID id, str|None context=None)
 
None delete (self, _MessageID id, str|None context=None)
 
None update (self, Catalog template, bool no_fuzzy_matching=False, bool update_header_comment=False, bool keep_user_comments=True, bool update_creation_date=True)
 
bool is_identical (self, Catalog other)
 

Public Attributes

 domain
 
 project
 
 version
 
 copyright_holder
 
 msgid_bugs_address
 
 last_translator
 
 language_team
 
 charset
 
 creation_date
 
 revision_date
 
 fuzzy
 
 plural_forms
 

Protected Member Functions

None _set_locale (self, Locale|str|None locale)
 
Locale|None _get_locale (self)
 
str|None _get_locale_identifier (self)
 
str _get_header_comment (self)
 
None _set_header_comment (self, str|None string)
 
list[tuple[str, str]] _get_mime_headers (self)
 
None _set_mime_headers (self, Iterable[tuple[str, str]] headers)
 
str _to_fuzzy_match_key (self, tuple[str, str]|str key)
 
tuple[str, str]|str _key_for (self, _MessageID id, str|None context=None)
 

Protected Attributes

 _header_comment
 
 _num_plurals
 
 _plural_expr
 
 _locale_identifier
 
 _locale
 
 _messages
 

Properties

 locale = property(_get_locale, _set_locale)
 
 locale_identifier = property(_get_locale_identifier)
 
 header_comment = property(_get_header_comment, _set_header_comment, doc=)
 
 mime_headers = property(_get_mime_headers, _set_mime_headers, doc=)
 

Detailed Description

Representation of a message catalog.

Constructor & Destructor Documentation

◆ __init__()

None babel.messages.catalog.Catalog.__init__ (   self,
Locale | str | None   locale = None,
str | None   domain = None,
str | None   header_comment = DEFAULT_HEADER,
str | None   project = None,
str | None   version = None,
str | None   copyright_holder = None,
str | None   msgid_bugs_address = None,
datetime.datetime | str | None   creation_date = None,
datetime.datetime | datetime.time | float | str | None   revision_date = None,
str | None   last_translator = None,
str | None   language_team = None,
str | None   charset = None,
bool   fuzzy = True 
)
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

Member Function Documentation

◆ __contains__()

bool babel.messages.catalog.Catalog.__contains__ (   self,
_MessageID  id 
)
Return whether the catalog has a message with the specified ID.

◆ __delitem__()

None babel.messages.catalog.Catalog.__delitem__ (   self,
_MessageID  id 
)
Delete the message with the specified ID.

◆ __getitem__()

Message babel.messages.catalog.Catalog.__getitem__ (   self,
_MessageID  id 
)
Return the message with the specified ID.

:param id: the message ID

◆ __iter__()

Iterator[Message] babel.messages.catalog.Catalog.__iter__ (   self)
Iterates through all the entries in the catalog, in the order they
were added, yielding a `Message` object for every entry.

:rtype: ``iterator``

◆ __len__()

int babel.messages.catalog.Catalog.__len__ (   self)
The number of messages in the catalog.

This does not include the special ``msgid ""`` entry.

◆ __setitem__()

None babel.messages.catalog.Catalog.__setitem__ (   self,
_MessageID  id,
Message  message 
)
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

◆ _key_for()

tuple[str, str] | str babel.messages.catalog.Catalog._key_for (   self,
_MessageID  id,
str | None   context = None 
)
protected
The key for a message is just the singular ID even for pluralizable
messages, but is a ``(msgid, msgctxt)`` tuple for context-specific
messages.

◆ _to_fuzzy_match_key()

str babel.messages.catalog.Catalog._to_fuzzy_match_key (   self,
tuple[str, str] | str  key 
)
protected
Converts a message key to a string suitable for fuzzy matching.

◆ add()

Message babel.messages.catalog.Catalog.add (   self,
_MessageID  id,
_MessageID | None   string = None,
Iterable[tuple[str, int]]   locations = (),
Iterable[str]   flags = (),
Iterable[str]   auto_comments = (),
Iterable[str]   user_comments = (),
_MessageID   previous_id = (),
int | None   lineno = None,
str | None   context = None 
)
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

◆ check()

Iterable[tuple[Message, list[TranslationError]]] babel.messages.catalog.Catalog.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: ``generator`` of ``(message, errors)``

◆ delete()

None babel.messages.catalog.Catalog.delete (   self,
_MessageID  id,
str | None   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

◆ get()

Message | None babel.messages.catalog.Catalog.get (   self,
_MessageID  id,
str | None   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

◆ is_identical()

bool babel.messages.catalog.Catalog.is_identical (   self,
Catalog  other 
)
Checks if catalogs are identical, taking into account messages and
headers.

◆ num_plurals()

int babel.messages.catalog.Catalog.num_plurals (   self)
The number of plurals used by the catalog or locale.

>>> Catalog(locale='en').num_plurals
2
>>> Catalog(locale='ga').num_plurals
5

:type: `int`

◆ plural_expr()

str babel.messages.catalog.Catalog.plural_expr (   self)
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`

◆ plural_forms()

str babel.messages.catalog.Catalog.plural_forms (   self)
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`

◆ update()

None babel.messages.catalog.Catalog.update (   self,
Catalog  template,
bool   no_fuzzy_matching = False,
bool   update_header_comment = False,
bool   keep_user_comments = True,
bool   update_creation_date = True 
)
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
:param update_header_comment: whether to copy the header comment from the template
:param keep_user_comments: whether to keep user comments from the old catalog
:param update_creation_date: whether to copy the creation date from the template

The documentation for this class was generated from the following file: