Commit 17cdbe1e authored by Michal Čihař's avatar Michal Čihař

Improve parsing of flags from Gettext PO files

As translate-toolkit does no parsing here (it just throws at us whole
comment lines), we need to do some processing to get nicely formatted
flags (fixes #276).

While working with them, we can also remove fuzzy flag, as it is already
represented by boolean flag within the unit (fixes #275).
parent e9f56b14
......@@ -37,6 +37,7 @@ import __builtin__
FILE_FORMATS = {}
FLAGS_RE = re.compile(r'\b[-\w]+\b')
def register_fileformat(fileformat):
......@@ -73,15 +74,30 @@ class FileUnit(object):
return ''
return ', '.join(self.mainunit.getlocations())
def reformat_flags(self, typecomments):
'''
Processes flags from PO file to nicer form.
'''
# Grab flags
flags = set(FLAGS_RE.findall('\n'.join(typecomments)))
# Discard fuzzy flag, we don't care about that one
flags.discard('fuzzy')
# Join into string
return ', '.join(flags)
def get_flags(self):
'''
Returns flags (typecomments) from units.
This is Gettext (po) specific feature.
'''
# Merge flags
if hasattr(self.unit, 'typecomments'):
return ', '.join(self.unit.typecomments)
return self.reformat_flags(self.unit.typecomments)
elif hasattr(self.template, 'typecomments'):
return ', '.join(self.template.typecomments)
return self.reformat_flags(self.template.typecomments)
else:
return ''
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment