language on explanation support + explanation as new model + homonymy refactored as a double list
This commit is contained in:
		
							parent
							
								
									a07b35c6a8
								
							
						
					
					
						commit
						1770932a14
					
				| @ -156,7 +156,17 @@ | ||||
|             vertical-align: super; | ||||
|             font-size: 0.7em; | ||||
|           } | ||||
|           .translation-explanation:not(:empty) { | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         .translation-add { | ||||
|           .translation-element-margin(); | ||||
|           .translation-button(); | ||||
|         } | ||||
|       } | ||||
|     } | ||||
| 
 | ||||
|     .explanations:not(:empty) { | ||||
|       font-style: italic; | ||||
| 
 | ||||
|       &:before { | ||||
| @ -166,14 +176,6 @@ | ||||
|         content: ']'; | ||||
|       } | ||||
|     } | ||||
|         } | ||||
| 
 | ||||
|         .translation-add { | ||||
|           .translation-element-margin(); | ||||
|           .translation-button(); | ||||
|         } | ||||
|       } | ||||
|     } | ||||
| 
 | ||||
|     .example { | ||||
|       clear: left; | ||||
|  | ||||
| @ -153,16 +153,11 @@ def export_translation(doc, translation): | ||||
|     explanationList = doc.createElement("explanationList") | ||||
| 
 | ||||
|     for explanation in translation.explanationList: | ||||
|         el = doc.createElement("explanation") | ||||
|         el.textContent = explanation | ||||
|         explanationList.appendChild(el) | ||||
|         explanationList.appendChild(explanation.export(doc)) | ||||
| 
 | ||||
|     translation_xml.appendChild(explanationList) | ||||
| 
 | ||||
| 
 | ||||
|     explanation = doc.createElement("explanation") | ||||
|     explanation.textContent = translation.explanation | ||||
|     translation_xml.appendChild(explanation) | ||||
| 
 | ||||
|     return translation_xml | ||||
| 
 | ||||
|  | ||||
| @ -10,16 +10,16 @@ def generic_list_getter(): | ||||
|     return result | ||||
| 
 | ||||
| # Formats data from inputs to name-value objects | ||||
| def homonymy_list_getter(): | ||||
| def double_list_getter(firstParameter, secondParameter): | ||||
|     result = [] | ||||
|     for row in document.getElementsByClassName("label-list-row"): | ||||
|         value = row.querySelector(".value-input").value | ||||
|         name = row.querySelector(".name-input").value | ||||
|     for row in document.getElementsByClassName("double-list-row"): | ||||
|         firstValue = row.querySelector("." + firstParameter + "-input").value | ||||
|         secondValue = row.querySelector("." + secondParameter + "-input").value | ||||
| 
 | ||||
|         if ("" in [name, value]): | ||||
|         if ("" in [firstValue, secondValue]): | ||||
|             continue | ||||
| 
 | ||||
|         result.append({"name": name, "value": value}) | ||||
|         result.append({firstParameter: firstValue, secondParameter: secondValue}) | ||||
| 
 | ||||
|     return result | ||||
| 
 | ||||
|  | ||||
| @ -90,7 +90,7 @@ class EditVariants(Message): | ||||
| 
 | ||||
| class EditHomonymy(Message): | ||||
|     def update_model(self, model): | ||||
|         homonymy = common_accessors.homonymy_list_getter() | ||||
|         homonymy = common_accessors.double_list_getter("value", "name") | ||||
|         model.entry.homonymy = homonymy | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										22
									
								
								src/model/explanation.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/model/explanation.py
									
									
									
									
									
										Normal 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 | ||||
| @ -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) | ||||
| 
 | ||||
|  | ||||
| @ -49,7 +49,7 @@ def generic_list_editor(title, element_list_getter): | ||||
| 
 | ||||
| def homonymy_editor(title, current_labels): | ||||
|     def split_line2(left, right): | ||||
|         cls = "flex.two{}".format(".label-list-row") | ||||
|         cls = "flex.two{}".format(".double-list-row") | ||||
|         return h("div.{}".format(cls), {}, [ | ||||
|             h("div.half", {}, left), h("div.half", {}, right)]) | ||||
| 
 | ||||
| @ -67,6 +67,28 @@ def homonymy_editor(title, current_labels): | ||||
| 
 | ||||
|     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 split_line3(left, center, right, is_llr=True): | ||||
|         cls = "flex.three{}".format(".label-list-row" if is_llr else "") | ||||
|  | ||||
| @ -21,7 +21,7 @@ def edit_translation(translation, parent, cluster_idx, num_clusters, cls): | ||||
|     content.extend([ | ||||
|         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 | ||||
|     options = [h("option", {"props": {"selected": idx == cluster_idx}}, str(idx + 1)) for idx in range(num_clusters + 1)] | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user