/* * Deserialization: */ public void Apply() { // Read *.xml file: XDocument xmlDoc = XDocument.Load(this.filePath); XElement xmlRoot = xmlDoc.Element("Language"); foreach (LocalizedForm form in Localization.LocalizedForms) { XElement xmlForm = xmlRoot.Element(form.Form.Name); if (xmlForm == null) { throw new InvalidXmlException($"Couldn't find <{form.Form.Name}>"); } // Set title, if it exists: if (xmlForm.Attribute("title") != null) { form.Form.Text = xmlForm.Attribute("title").Value; } // Forms: DeserializeDictionaries(xmlRoot); DeserializeControls(xmlForm, form.Form, form.ToolTip); foreach (Control subControl in form.SpecialControls) { DeserializeControl(xmlForm, subControl, form.ToolTip); } // Message boxes: XElement xmlMsgBox = xmlRoot.Element("Messageboxes"); if (xmlMsgBox != null) { MsgBox.Deserialize(xmlMsgBox); } // Strings: XElement xmlStrings = xmlRoot.Element("Strings"); if (xmlStrings != null) { Localization.DeserializeStrings(xmlStrings); } // Drop downs: XElement xmlDropDowns = xmlRoot.Element("Dropdowns"); if (xmlDropDowns != null) { DropDown.DeserializeAll(xmlDropDowns); } } }
/* * Deserialization: */ public void Apply() { try { // Read *.xml file: XDocument xmlDoc = XDocument.Load(this.filePath); XElement xmlRoot = xmlDoc.Element("Language"); ignoreTooltipsOfTheseControls = LinkedTweaks.GetListOfLinkedControlNames(); // Translate each form individually: foreach (LocalizedForm form in Localization.LocalizedForms) { XElement xmlForm = xmlRoot.Element(form.Form.Name); // Ignore non-existing forms if (xmlForm == null) { continue; // throw new InvalidXmlException($"Couldn't find <{form.Form.Name}>"); } // Set title, if it exists: if (xmlForm.Attribute("title") != null) { form.Form.Text = xmlForm.Attribute("title").Value; } // Forms: DeserializeDictionaries(xmlForm); // TODO: xmlRoot replaced with xmlForm. Good idea? DeserializeControls(xmlForm, form.Form, form.ToolTip); foreach (Control subControl in form.SpecialControls) { DeserializeControl(xmlForm, subControl, form.ToolTip); } // Message boxes: XElement xmlMsgBox = xmlRoot.Element("Messageboxes"); if (xmlMsgBox != null) { MsgBox.Deserialize(xmlMsgBox); } // Strings: XElement xmlStrings = xmlRoot.Element("Strings"); if (xmlStrings != null) { Localization.DeserializeStrings(xmlStrings); } // TODO: Generalize this. No outside references, plz: // TODO: Doesn't make sense to deserialize them multiple times: // Drop downs: XElement xmlDropDowns = xmlRoot.Element("Dropdowns"); if (xmlDropDowns != null) { DropDown.DeserializeAll(xmlDropDowns); } // Tweak descriptions: XElement xmlTweakDescriptions = xmlRoot.Element("TweakDescriptions"); if (xmlTweakDescriptions != null) { LinkedTweaks.DeserializeTweakDescriptionList(xmlTweakDescriptions); } if (form.ToolTip != null) { LinkedTweaks.SetToolTips(); // TODO: No need to call it per form anymore } } // Call event handler: if (LanguageChanged != null) { TranslationEventArgs e = new TranslationEventArgs(); e.HasAuthor = this.Author != ""; //e.ActiveTranslation = this; LanguageChanged(this, e); } } catch (Exception exc) { MsgBox.Show("Loading translation failed", $"The translation '{Path.GetFileNameWithoutExtension(filePath)}' couldn't be loaded.\n{exc.GetType()}: {exc.Message}", MessageBoxIcon.Error); } }