Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

customizable entries #147

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 46 additions & 12 deletions polib.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,12 +872,34 @@ def __unicode__(self, wrapwidth=78):
delflag = ''
ret = []
# write the msgctxt if any
self._unicode_msgctxt(ret, wrapwidth=wrapwidth, delflag=delflag)
# write the msgid
self._unicode_msgid(ret, wrapwidth=wrapwidth, delflag=delflag)
# write the msgid_plural if any
self._unicode_msgid_plural(ret, wrapwidth=wrapwidth, delflag=delflag)

ret.append('')
ret = u('\n').join(ret)
return ret

def _unicode_msgctxt(self, ret, **kwargs):
wrapwidth = kwargs.get("wrapwidth")
delflag = kwargs.get("delflag")

if self.msgctxt is not None:
ret += self._str_field("msgctxt", delflag, "", self.msgctxt,
wrapwidth)
# write the msgid

def _unicode_msgid(self, ret, **kwargs):
wrapwidth = kwargs .get("wrapwidth")
delflag = kwargs.get("delflag")

ret += self._str_field("msgid", delflag, "", self.msgid, wrapwidth)
# write the msgid_plural if any

def _unicode_msgid_plural(self, ret, **kwargs):
wrapwidth = kwargs .get("wrapwidth")
delflag = kwargs.get("delflag")

if self.msgid_plural:
ret += self._str_field("msgid_plural", delflag, "",
self.msgid_plural, wrapwidth)
Expand All @@ -895,9 +917,6 @@ def __unicode__(self, wrapwidth=78):
# otherwise write the msgstr
ret += self._str_field("msgstr", delflag, "", self.msgstr,
wrapwidth)
ret.append('')
ret = u('\n').join(ret)
return ret

if PY3:
def __str__(self):
Expand Down Expand Up @@ -1006,6 +1025,23 @@ def __unicode__(self, wrapwidth=78):
"""
ret = []
# comments first, if any (with text wrapping as xgettext does)
self._unicode_comments(ret, wrapwidth=wrapwidth)

# occurrences (with text wrapping as xgettext does)
self._unicode_occurrences(ret, wrapwidth=wrapwidth)

# flags (TODO: wrapping ?)
self._unicode_flags(ret, wrapwidth=wrapwidth)

# previous context and previous msgid/msgid_plural
self._unicode_previous(ret, wrapwidth=wrapwidth)

ret.append(_BaseEntry.__unicode__(self, wrapwidth))
ret = u('\n').join(ret)
return ret

def _unicode_comments(self, ret, **kwargs):
wrapwidth = kwargs.get('wrapwidth')
if self.obsolete:
comments = [('tcomment', '# ')]
else:
Expand All @@ -1025,7 +1061,8 @@ def __unicode__(self, wrapwidth=78):
else:
ret.append('%s%s' % (c[1], comment))

# occurrences (with text wrapping as xgettext does)
def _unicode_occurrences(self, ret, **kwargs):
wrapwidth = kwargs.get('wrapwidth')
if not self.obsolete and self.occurrences:
filelist = []
for fpath, lineno in self.occurrences:
Expand All @@ -1049,11 +1086,12 @@ def __unicode__(self, wrapwidth=78):
else:
ret.append('#: ' + filestr)

# flags (TODO: wrapping ?)
def _unicode_flags(self, ret, **kwargs):
if self.flags:
ret.append('#, %s' % ', '.join(self.flags))

# previous context and previous msgid/msgid_plural
def _unicode_previous(self, ret, **kwargs):
wrapwidth = kwargs.get('wrapwidth')
fields = ['previous_msgctxt', 'previous_msgid',
'previous_msgid_plural']
if self.obsolete:
Expand All @@ -1065,10 +1103,6 @@ def __unicode__(self, wrapwidth=78):
if val is not None:
ret += self._str_field(f, prefix, "", val, wrapwidth)

ret.append(_BaseEntry.__unicode__(self, wrapwidth))
ret = u('\n').join(ret)
return ret

def __cmp__(self, other):
"""
Called by comparison operations if rich comparison is not defined.
Expand Down