diff --git a/src/message/show_messages.py b/src/message/show_messages.py index 11d246f..4e0a668 100644 --- a/src/message/show_messages.py +++ b/src/message/show_messages.py @@ -62,7 +62,7 @@ class ShowAddTranslation(ClickMessage): def update_model(self, model): chosen_sense_or_example = self.get_arg(0) - translation = Translation.new_empty() + translation = Translation() translation.make_copy() model.modal_set(lambda: modals.edit_translation( translation, diff --git a/src/model/translation.py b/src/model/translation.py index 8b4f489..e84d593 100644 --- a/src/model/translation.py +++ b/src/model/translation.py @@ -1,5 +1,9 @@ from model.tags import import_label_list -from model.data import Data as Editable +from model.data import Data + +from lib.snabbdom import h +from view.utils import clean_label +import message as M def from_container_list(translation_list_container_xml): @@ -12,7 +16,9 @@ def from_container_list(translation_list_container_xml): num_cluster = int(translation_xml.getAttribute("cluster")) max_num_cluster = max(max_num_cluster, num_cluster) - translations.append((num_cluster, Translation(translation_xml))) + t = Translation() + t.import_xml(translation_xml) + translations.append((num_cluster, t)) result = [[] for _ in range(max_num_cluster)] for clusterNum, translation in translations: @@ -21,23 +27,46 @@ def from_container_list(translation_list_container_xml): return result -class Translation(Editable): +class Translation(Data): def __init__(self, translation_xml): + self.translation = "" + self.source = "" + self.targetLang = "" + self.explanation = "" + self.tags = [] + + def import_xml(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) + + def view(self, model): + elements = [] + + if self.tags: + tags = h("div.translation-tags", {}, [ + h("span", {"attr": {"title": key}}, clean_label(value)) + for key, value in self.tags]) + elements.append(tags) + + elements.append(h("span.translation-text", {}, self.translation)) + 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.explanation)) + + return h("div.translation-div", {"on": {"click": M.msg(M.ShowTranslationMenu, self) }}, elements) + + def is_empty(self): result = True result = result and self.translation == ""