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

View File

@ -156,7 +156,17 @@
vertical-align: super; vertical-align: super;
font-size: 0.7em; font-size: 0.7em;
} }
.translation-explanation:not(:empty) {
}
.translation-add {
.translation-element-margin();
.translation-button();
}
}
}
.explanations:not(:empty) {
font-style: italic; font-style: italic;
&:before { &:before {
@ -166,14 +176,6 @@
content: ']'; content: ']';
} }
} }
}
.translation-add {
.translation-element-margin();
.translation-button();
}
}
}
.example { .example {
clear: left; clear: left;

View File

@ -153,16 +153,11 @@ def export_translation(doc, translation):
explanationList = doc.createElement("explanationList") explanationList = doc.createElement("explanationList")
for explanation in translation.explanationList: for explanation in translation.explanationList:
el = doc.createElement("explanation") explanationList.appendChild(explanation.export(doc))
el.textContent = explanation
explanationList.appendChild(el)
translation_xml.appendChild(explanationList) translation_xml.appendChild(explanationList)
explanation = doc.createElement("explanation")
explanation.textContent = translation.explanation
translation_xml.appendChild(explanation)
return translation_xml return translation_xml

View File

@ -10,16 +10,16 @@ def generic_list_getter():
return result return result
# Formats data from inputs to name-value objects # Formats data from inputs to name-value objects
def homonymy_list_getter(): def double_list_getter(firstParameter, secondParameter):
result = [] result = []
for row in document.getElementsByClassName("label-list-row"): for row in document.getElementsByClassName("double-list-row"):
value = row.querySelector(".value-input").value firstValue = row.querySelector("." + firstParameter + "-input").value
name = row.querySelector(".name-input").value secondValue = row.querySelector("." + secondParameter + "-input").value
if ("" in [name, value]): if ("" in [firstValue, secondValue]):
continue continue
result.append({"name": name, "value": value}) result.append({firstParameter: firstValue, secondParameter: secondValue})
return result return result

View File

@ -90,7 +90,7 @@ class EditVariants(Message):
class EditHomonymy(Message): class EditHomonymy(Message):
def update_model(self, model): def update_model(self, model):
homonymy = common_accessors.homonymy_list_getter() homonymy = common_accessors.double_list_getter("value", "name")
model.entry.homonymy = homonymy model.entry.homonymy = homonymy

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.tags import import_label_list
from model.explanation import Explanation
from model.data import Data from model.data import Data
from lib.snabbdom import h from lib.snabbdom import h
@ -46,11 +47,11 @@ class Translation(Data):
explanationList = translation_xml.querySelectorAll("explanationList explanation") explanationList = translation_xml.querySelectorAll("explanationList explanation")
for explanation in explanationList: for explanation_dom in explanationList:
self.explanationList.append(explanation.textContent if explanation else "") 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) self.tags = import_label_list("labelList label", translation_xml)
def view(self, model): def view(self, model):
@ -66,10 +67,9 @@ class Translation(Data):
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 ""
# elements.append(h("span{}".format(explanation_class), {}, self.explanations)) explanations = [explanation.value for explanation in self.explanationList]
elements.append(h("span{}".format(explanation_class), {}, ", ".join(self.explanationList))) elements.append(h("span.explanations", {}, ", ".join(explanations)))
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)

View File

@ -49,7 +49,7 @@ def generic_list_editor(title, element_list_getter):
def homonymy_editor(title, current_labels): def homonymy_editor(title, current_labels):
def split_line2(left, right): def split_line2(left, right):
cls = "flex.two{}".format(".label-list-row") cls = "flex.two{}".format(".double-list-row")
return h("div.{}".format(cls), {}, [ return h("div.{}".format(cls), {}, [
h("div.half", {}, left), h("div.half", {}, right)]) h("div.half", {}, left), h("div.half", {}, right)])
@ -67,6 +67,28 @@ def homonymy_editor(title, current_labels):
return content return content
def explanation_editor(title, current_labels):
def split_line2(left, right):
cls = "flex.two{}".format(".double-list-row")
return h("div.{}".format(cls), {}, [
h("div.four-fifth", {}, left), h("div.fifth", {}, right)])
content = [h("p", {}, title)]
for i, explanation in enumerate(current_labels()):
language = []
value = []
language.append(h("label", {"attrs": {"for": i}}, "Language:"))
language.append(h("input.language-input", {"props": {"type": "text", "value": explanation["language"], "id": i}}, ""))
value.append(h("label", {"attrs": {"for": i + "-value"}}, "Value:"))
value.append(h("input.value-input", {"props": {"type": "text", "value": explanation["value"], "id": i + "-value"}}, ""))
content.append(split_line2(value, language))
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, current_labels)}}, "+"))
return content
def label_list_editor(current_labels, add_label_message_class): def label_list_editor(current_labels, add_label_message_class):
def split_line3(left, center, right, is_llr=True): def split_line3(left, center, right, is_llr=True):
cls = "flex.three{}".format(".label-list-row" if is_llr else "") cls = "flex.three{}".format(".label-list-row" if is_llr else "")

View File

@ -21,7 +21,7 @@ def edit_translation(translation, parent, cluster_idx, num_clusters, cls):
content.extend([ content.extend([
split_line2("Prevedek:", h("textarea#etv", {"props": {"value": translation.translation}}, ""))]) split_line2("Prevedek:", h("textarea#etv", {"props": {"value": translation.translation}}, ""))])
content.extend(generic_list_editor("Razlage:", lambda: translation.explanationList)) content.extend(explanation_editor("Razlage:", lambda: translation.explanationList))
# cluster number # cluster number
options = [h("option", {"props": {"selected": idx == cluster_idx}}, str(idx + 1)) for idx in range(num_clusters + 1)] options = [h("option", {"props": {"selected": idx == cluster_idx}}, str(idx + 1)) for idx in range(num_clusters + 1)]