Commit a79c4baf authored by Michal Čihař's avatar Michal Čihař

Move Xliff specific code to the separate class

Issue #816
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 1d6d2192
......@@ -106,8 +106,7 @@ class FileUnit(object):
'''
# JSON, XLIFF and PHP are special in ttkit - it uses locations for what
# is context in other formats
if (isinstance(self.mainunit, xliffunit) or
isinstance(self.mainunit, propunit) or
if (isinstance(self.mainunit, propunit) or
isinstance(self.mainunit, phpunit)):
return ''
result = ', '.join(self.mainunit.getlocations())
......@@ -234,15 +233,7 @@ class FileUnit(object):
Returns context of message. In some cases we have to use
ID here to make all backends consistent.
'''
# XLIFF is special in ttkit - it uses locations for what
# is context in other formats
if isinstance(self.mainunit, xliffunit):
context = self.mainunit.getlocations()
if len(context) == 0:
return ''
else:
return context[0]
elif isinstance(self.mainunit, pounit) and self.template is not None:
if isinstance(self.mainunit, pounit) and self.template is not None:
# Monolingual JSON files
return self.template.getid()
else:
......@@ -346,6 +337,28 @@ class FileUnit(object):
self.unit.markfuzzy(fuzzy)
class XliffUnit(FileUnit):
def get_context(self):
'''
Returns context of message. In some cases we have to use
ID here to make all backends consistent.
XLIFF is special in ttkit - it uses locations for what
is context in other formats
'''
context = self.mainunit.getlocations()
if len(context) == 0:
return ''
else:
return context[0]
def get_locations(self):
'''
Returns comma separated list of locations.
'''
return ''
class MonolingualIDUnit(FileUnit):
def get_context(self):
if self.template is not None:
......@@ -911,6 +924,7 @@ class XliffFormat(FileFormat):
format_id = 'xliff'
loader = ('xliff', 'xlifffile')
autoload = ('.xlf', '.xliff')
unit_class = XliffUnit
@classmethod
def supports_new_language(cls):
......
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