glossary: added 'to_str()' function
This commit is contained in:
parent
1b39fb1ac5
commit
3cca32a40b
@ -138,3 +138,20 @@ class Glossary:
|
||||
self.entries[parts[0]] = parts[1]
|
||||
except Exception as 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