Able to remove empty translations

This commit is contained in:
Ozbolt Menegatti 2020-01-26 17:10:27 +01:00
parent efe7ebb1e1
commit 9517bb4b63
3 changed files with 27 additions and 1 deletions

View File

@ -18,6 +18,11 @@ class EditTranslation(DataChgClickMessage):
# common_accessors.label_list_getter() # common_accessors.label_list_getter()
self.translation.tags = common_accessors.label_list_getter() self.translation.tags = common_accessors.label_list_getter()
# check if empty, remove!
if self.translation.is_empty():
model.entry.remove_translation(self.translation)
return
new_cluster_idx = int(document.getElementById("cluster-num").value) - 1 new_cluster_idx = int(document.getElementById("cluster-num").value) - 1
self.handle_cluster_change(new_cluster_idx, model) self.handle_cluster_change(new_cluster_idx, model)

View File

@ -36,3 +36,15 @@ class Entry(Editable):
def get_measure_text(self): def get_measure_text(self):
return self.measure["text"] if "text" in self.measure else "" return self.measure["text"] if "text" in self.measure else ""
def remove_translation(self, translation):
for sense in self.senses:
for cluster in sense.translations:
if translation in cluster:
cluster.remove(translation)
return
for example in sense.examples:
for cluster in example.translations:
if translation in cluster:
cluster.remove(translation)
return

View File

@ -38,3 +38,12 @@ class Translation(Editable):
self.explanation = explanation.textContent if explanation else "" self.explanation = explanation.textContent if explanation else ""
self.tags = import_label_list("labelList label", translation_xml) self.tags = import_label_list("labelList label", translation_xml)
def is_empty(self):
result = True
result = result and self.translation == ""
# next two are not checked as the also can not be deleted via gui
# result = result and self.source == ""
# result = result and self.targetLang == ""
result = result and self.explanation == ""
result = result and len(self.tags) == 0
return result