Explanation list support

pull/5/head
matic_t 4 years ago
parent 8b7c282fdf
commit 964dc3f788

@ -150,6 +150,17 @@ def export_translation(doc, translation):
actual_t.setAttribute("source", translation.source) actual_t.setAttribute("source", translation.source)
translation_xml.appendChild(actual_t) translation_xml.appendChild(actual_t)
explanationList = doc.createElement("explanationList")
for explanation in translation.explanationList:
console.log(explanation)
el = doc.createElement("explanation")
el.textContent = explanation
explanationList.appendChild(el)
translation_xml.appendChild(explanationList)
explanation = doc.createElement("explanation") explanation = doc.createElement("explanation")
explanation.textContent = translation.explanation explanation.textContent = translation.explanation
translation_xml.appendChild(explanation) translation_xml.appendChild(explanation)

@ -9,21 +9,21 @@ import message as M
def from_container_list(translation_list_container_xml): def from_container_list(translation_list_container_xml):
translations = [] translations = []
max_num_cluster = 0 max_num_cluster = 0
for translation_xml in translation_list_container_xml: for translation_xml in translation_list_container_xml:
num_cluster = 1 # default cluster num_cluster = 1 # default cluster
if translation_xml.hasAttribute("cluster"): if translation_xml.hasAttribute("cluster"):
num_cluster = int(translation_xml.getAttribute("cluster")) num_cluster = int(translation_xml.getAttribute("cluster"))
max_num_cluster = max(max_num_cluster, num_cluster) max_num_cluster = max(max_num_cluster, num_cluster)
t = Translation() t = Translation()
t.import_xml(translation_xml) t.import_xml(translation_xml)
translations.append((num_cluster, t)) translations.append((num_cluster, t))
result = [[] for _ in range(max_num_cluster)] result = [[] for _ in range(max_num_cluster)]
for clusterNum, translation in translations: for clusterNum, translation in translations:
result[clusterNum - 1].append(translation) result[clusterNum - 1].append(translation)
return result return result
@ -33,40 +33,47 @@ class Translation(Data):
self.source = "" self.source = ""
self.targetLang = "" self.targetLang = ""
self.explanation = "" self.explanation = ""
self.explanationList = []
self.tags = [] self.tags = []
def import_xml(self, translation_xml): def import_xml(self, translation_xml):
translation = translation_xml.querySelector("translation") translation = translation_xml.querySelector("translation")
if translation: if translation:
self.translation = translation.textContent self.translation = translation.textContent
self.source = translation.getAttribute("source") if translation.hasAttribute("source") else "" self.source = translation.getAttribute("source") if translation.hasAttribute("source") else ""
self.targetLang = translation.getAttribute("targetLang") if translation.hasAttribute("targetLang") else "" self.targetLang = translation.getAttribute("targetLang") if translation.hasAttribute("targetLang") else ""
explanationList = translation_xml.querySelectorAll("explanationList explanation")
for explanation in explanationList:
self.explanationList.append(explanation.textContent if explanation else "")
explanation = translation_xml.querySelector("explanation") explanation = translation_xml.querySelector("explanation")
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 view(self, model): def view(self, model):
elements = [] elements = []
if self.tags: if self.tags:
tags = h("div.translation-tags", {}, [ tags = h("div.translation-tags", {}, [
h("span", {"attr": {"title": key}}, clean_label(value)) h("span", {"attr": {"title": key}}, clean_label(value))
for key, value in self.tags]) for key, value in self.tags])
elements.append(tags) elements.append(tags)
elements.append(h("span.translation-text", {}, self.translation)) elements.append(h("span.translation-text", {}, self.translation))
if self.source: if self.source:
elements.append(h("span.translation-source", {}, self.source)) elements.append(h("span.translation-source", {}, self.source))
explanation_class = ".translation-explanation" if self.translation else "" explanation_class = ".translation-explanation" if self.translation else ""
elements.append(h("span{}".format(explanation_class), {}, self.explanation))
# elements.append(h("span{}".format(explanation_class), {}, self.explanations))
elements.append(h("span{}".format(explanation_class), {}, ", ".join(self.explanationList)))
return h("div.translation-div", {"on": {"click": M.msg(M.ShowTranslationMenu, self) }}, elements) return h("div.translation-div", {"on": {"click": M.msg(M.ShowTranslationMenu, self) }}, elements)
def is_empty(self): def is_empty(self):
result = True result = True
result = result and self.translation == "" result = result and self.translation == ""

Loading…
Cancel
Save