glossary: added 'to_str()' function
This commit is contained in:
parent
86295c6492
commit
15f6e819e5
@ -138,3 +138,20 @@ class Glossary:
|
|||||||
self.entries[parts[0]] = parts[1]
|
self.entries[parts[0]] = parts[1]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise GlossaryError(f"Error importing TSV: {e}")
|
raise GlossaryError(f"Error importing TSV: {e}")
|
||||||
|
|
||||||
|
def to_str(self, with_entries: bool = False) -> str:
|
||||||
|
"""
|
||||||
|
Return the current glossary as a string.
|
||||||
|
"""
|
||||||
|
output: list[str] = []
|
||||||
|
output.append(f'{self.name} (ID: {self.ID}):')
|
||||||
|
if self.desc:
|
||||||
|
output.append('- ' + self.desc)
|
||||||
|
output.append(f'- Languages: {self.source_lang} -> {self.target_lang}')
|
||||||
|
if with_entries:
|
||||||
|
output.append('- Entries:')
|
||||||
|
for source, target in self.entries.items():
|
||||||
|
output.append(f' {source} : {target}')
|
||||||
|
else:
|
||||||
|
output.append(f'- Entries: {len(self.entries)}')
|
||||||
|
return '\n'.join(output)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user