Module polib :: Class POEntry
[hide private]
[frames] | no frames]

Class POEntry

source code

object --+    
         |    
_BaseEntry --+
             |
            POEntry

Represents a po file entry.

**Examples**:

>>> entry = POEntry(msgid='Welcome', msgstr='Bienvenue')
>>> entry.occurrences = [('welcome.py', 12), ('anotherfile.py', 34)]
>>> print(entry)
#: welcome.py:12 anotherfile.py:34
msgid "Welcome"
msgstr "Bienvenue"
<BLANKLINE>
>>> entry = POEntry()
>>> entry.occurrences = [('src/some-very-long-filename-that-should-not-be-wrapped-even-if-it-is-larger-than-the-wrap-limit.c', 32), ('src/eggs.c', 45)]
>>> entry.comment = 'A plural translation. This is a very very very long line please do not wrap, this is just for testing comment wrapping...'
>>> entry.tcomment = 'A plural translation. This is a very very very long line please do not wrap, this is just for testing comment wrapping...'
>>> entry.flags.append('c-format')
>>> entry.msgid = 'I have spam but no egg !'
>>> entry.msgid_plural = 'I have spam and %d eggs !'
>>> entry.msgstr_plural[0] = "J'ai du jambon mais aucun oeuf !"
>>> entry.msgstr_plural[1] = "J'ai du jambon et %d oeufs !"
>>> print(entry)
#. A plural translation. This is a very very very long line please do not
#. wrap, this is just for testing comment wrapping...
# A plural translation. This is a very very very long line please do not wrap,
# this is just for testing comment wrapping...
#: src/some-very-long-filename-that-should-not-be-wrapped-even-if-it-is-larger-than-the-wrap-limit.c:32
#: src/eggs.c:45
#, c-format
msgid "I have spam but no egg !"
msgid_plural "I have spam and %d eggs !"
msgstr[0] "J'ai du jambon mais aucun oeuf !"
msgstr[1] "J'ai du jambon et %d oeufs !"
<BLANKLINE>
Instance Methods [hide private]
 
__init__(self, *args, **kwargs)
POEntry constructor.
source code
 
__str__(self, wrapwidth=78)
Return the string representation of the entry.
source code
 
__cmp__(self, other)
Called by comparison operations if rich comparison is not defined.
source code
 
translated(self)
Return True if the entry has been translated or False.
source code
 
merge(self, other)
Merge the current entry with the given pot entry.
source code

Inherited from _BaseEntry: __repr__

Inherited from _BaseEntry (private): _str_field

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, *args, **kwargs)
(Constructor)

source code 

POEntry constructor.

Overrides: object.__init__

__str__(self, wrapwidth=78)
(Informal representation operator)

source code 

Return the string representation of the entry.

Overrides: object.__str__

__cmp__(self, other)
(Comparison operator)

source code 

Called by comparison operations if rich comparison is not defined.

**Tests**: >>> a = POEntry(msgid='a', occurrences=[('b.py', 1), ('b.py', 3)]) >>> b = POEntry(msgid='b', occurrences=[('b.py', 1), ('b.py', 3)]) >>> c1 = POEntry(msgid='c1', occurrences=[('a.py', 1), ('b.py', 1)]) >>> c2 = POEntry(msgid='c2', occurrences=[('a.py', 1), ('a.py', 3)]) >>> po = POFile() >>> po.append(a) >>> po.append(b) >>> po.append(c1) >>> po.append(c2) >>> po.sort() >>> print(po) # msgid "" msgstr "" <BLANKLINE> #: a.py:1 a.py:3 msgid "c2" msgstr "" <BLANKLINE> #: a.py:1 b.py:1 msgid "c1" msgstr "" <BLANKLINE> #: b.py:1 b.py:3 msgid "a" msgstr "" <BLANKLINE> #: b.py:1 b.py:3 msgid "b" msgstr "" <BLANKLINE>