language on explanation support + explanation as new model + homonymy refactored as a double list

This commit is contained in:
matic_t
2020-08-06 03:47:52 -07:00
parent a07b35c6a8
commit 1770932a14
8 changed files with 84 additions and 43 deletions

22
src/model/explanation.py Normal file
View File

@@ -0,0 +1,22 @@
from model.data import Data
from lib.snabbdom import h
class Explanation(Data):
def __init__(self):
self.value = ""
self.language = ""
def import_dom(self, explanation_dom):
self.value = explanation_dom.textContent if explanation_dom else ""
self.language = explanation_dom.getAttribute("language") if explanation_dom.hasAttribute("language") else ""
def export(self, doc):
result = doc.createElement("explanation")
result.textContent = self.value
console.log(self.language)
if self.language != "": result.setAttribute('language', self.language)
return result

View File

@@ -1,4 +1,5 @@
from model.tags import import_label_list
from model.explanation import Explanation
from model.data import Data
from lib.snabbdom import h
@@ -46,11 +47,11 @@ class Translation(Data):
explanationList = translation_xml.querySelectorAll("explanationList explanation")
for explanation in explanationList:
self.explanationList.append(explanation.textContent if explanation else "")
for explanation_dom in explanationList:
explanation = Explanation()
explanation.import_dom(explanation_dom)
self.explanationList.append(explanation)
explanation = translation_xml.querySelector("explanation")
self.explanation = explanation.textContent if explanation else ""
self.tags = import_label_list("labelList label", translation_xml)
def view(self, model):
@@ -66,10 +67,9 @@ class Translation(Data):
if self.source:
elements.append(h("span.translation-source", {}, self.source))
explanation_class = ".translation-explanation" if self.translation else ""
# elements.append(h("span{}".format(explanation_class), {}, self.explanations))
elements.append(h("span{}".format(explanation_class), {}, ", ".join(self.explanationList)))
explanations = [explanation.value for explanation in self.explanationList]
elements.append(h("span.explanations", {}, ", ".join(explanations)))
return h("div.translation-div", {"on": {"click": M.msg(M.ShowTranslationMenu, self) }}, elements)