You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lexonomy_custom_editor/src/model/translation.py

41 lines
1.5 KiB

from model.tags import import_label_list
from model.editable import Editable
def from_container_list(translation_list_container_xml):
translations = []
max_num_cluster = 0
for translation_xml in translation_list_container_xml:
num_cluster = 1 # default cluster
if translation_xml.hasAttribute("cluster"):
num_cluster = int(translation_xml.getAttribute("cluster"))
max_num_cluster = max(max_num_cluster, num_cluster)
translations.append((num_cluster, Translation(translation_xml)))
result = [[] for _ in range(max_num_cluster)]
for clusterNum, translation in translations:
result[clusterNum - 1].append(translation)
return result
class Translation(Editable):
def __init__(self, translation_xml):
translation = translation_xml.querySelector("translation")
if translation:
self.translation = translation.textContent
self.source = translation.getAttribute("source") if translation.hasAttribute("source") else ""
self.targetLang = translation.getAttribute("targetLang") if translation.hasAttribute("targetLang") else ""
else:
self.translation = ""
self.source = ""
self.targetLang = ""
explanation = translation_xml.querySelector("explanation")
self.explanation = explanation.textContent if explanation else ""
self.tags = import_label_list("labelList label", translation_xml)