internal static Localization Deserialize(JsonObject jsonObject) { var codepage = jsonObject.GetValueOrDefault("codepage", 0); var culture = jsonObject.GetValueOrDefault <string>("culture"); var variables = new Dictionary <string, BindVariable>(); var variablesJson = jsonObject.GetValueOrDefault("variables", new JsonArray()); foreach (JsonObject variableJson in variablesJson) { var bindPath = BindVariable.Deserialize(variableJson); variables.Add(bindPath.Id, bindPath); } var controls = new Dictionary <string, LocalizedControl>(); var controlsJson = jsonObject.GetValueOrDefault <JsonObject>("controls"); if (controlsJson != null) { foreach (var controlJsonWithKey in controlsJson) { var control = LocalizedControl.Deserialize((JsonObject)controlJsonWithKey.Value); controls.Add(controlJsonWithKey.Key, control); } } return(new Localization(codepage, culture, variables, controls)); }
/// <summary> /// Get key for a localized control. /// </summary> /// <returns>The localized control id.</returns> public string GetKey() => LocalizedControl.GetKey(this.Dialog, this.Control);
/// <summary> /// Loads a localization file from a stream. /// </summary> /// <param name="reader">XmlReader where the intermediate is persisted.</param> /// <param name="tableDefinitions">Collection containing TableDefinitions to use when loading the localization file.</param> /// <returns>Returns the loaded localization.</returns> internal static Localization Read(XmlReader reader, TableDefinitionCollection tableDefinitions) { Debug.Assert("localization" == reader.LocalName); int codepage = 0; string culture = null; bool empty = reader.IsEmptyElement; while (reader.MoveToNextAttribute()) { switch (reader.Name) { case "codepage": codepage = Convert.ToInt32(reader.Value, CultureInfo.InvariantCulture); break; case "culture": culture = reader.Value; break; } } TableDefinition wixVariableTable = tableDefinitions["WixVariable"]; Dictionary <string, WixVariableRow> variables = new Dictionary <string, WixVariableRow>(); Dictionary <string, LocalizedControl> localizedControls = new Dictionary <string, LocalizedControl>(); if (!empty) { bool done = false; while (!done && reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: switch (reader.LocalName) { case "string": WixVariableRow row = Localization.ReadString(reader, wixVariableTable); variables.Add(row.Id, row); break; case "ui": LocalizedControl ui = Localization.ReadUI(reader); localizedControls.Add(ui.GetKey(), ui); break; default: throw new XmlException(); } break; case XmlNodeType.EndElement: done = true; break; } } if (!done) { throw new XmlException(); } } return(new Localization(codepage, culture, variables, localizedControls)); }
/// <summary> /// Writes a localization file into an XML format. /// </summary> /// <param name="writer">XmlWriter where the localization file should persist itself as XML.</param> internal void Write(XmlWriter writer) { writer.WriteStartElement(Localization.XmlElementName, Library.XmlNamespaceUri); if (-1 != this.Codepage) { writer.WriteAttributeString("codepage", this.Codepage.ToString(CultureInfo.InvariantCulture)); } if (!String.IsNullOrEmpty(this.Culture)) { writer.WriteAttributeString("culture", this.Culture); } foreach (WixVariableRow wixVariableRow in this.variables.Values) { writer.WriteStartElement("string", Library.XmlNamespaceUri); writer.WriteAttributeString("id", wixVariableRow.Id); if (wixVariableRow.Overridable) { writer.WriteAttributeString("overridable", "yes"); } writer.WriteCData(wixVariableRow.Value); writer.WriteEndElement(); } foreach (string controlKey in this.localizedControls.Keys) { writer.WriteStartElement("ui", Library.XmlNamespaceUri); string[] controlKeys = controlKey.Split('/'); string dialog = controlKeys[0]; string control = controlKeys[1]; if (!String.IsNullOrEmpty(dialog)) { writer.WriteAttributeString("dialog", dialog); } if (!String.IsNullOrEmpty(control)) { writer.WriteAttributeString("control", control); } LocalizedControl localizedControl = this.localizedControls[controlKey]; if (Common.IntegerNotSet != localizedControl.X) { writer.WriteAttributeString("x", localizedControl.X.ToString()); } if (Common.IntegerNotSet != localizedControl.Y) { writer.WriteAttributeString("y", localizedControl.Y.ToString()); } if (Common.IntegerNotSet != localizedControl.Width) { writer.WriteAttributeString("width", localizedControl.Width.ToString()); } if (Common.IntegerNotSet != localizedControl.Height) { writer.WriteAttributeString("height", localizedControl.Height.ToString()); } if (MsiInterop.MsidbControlAttributesRTLRO == (localizedControl.Attributes & MsiInterop.MsidbControlAttributesRTLRO)) { writer.WriteAttributeString("rightToLeft", "yes"); } if (MsiInterop.MsidbControlAttributesRightAligned == (localizedControl.Attributes & MsiInterop.MsidbControlAttributesRightAligned)) { writer.WriteAttributeString("rightAligned", "yes"); } if (MsiInterop.MsidbControlAttributesLeftScroll == (localizedControl.Attributes & MsiInterop.MsidbControlAttributesLeftScroll)) { writer.WriteAttributeString("leftScroll", "yes"); } if (!String.IsNullOrEmpty(localizedControl.Text)) { writer.WriteCData(localizedControl.Text); } writer.WriteEndElement(); } writer.WriteEndElement(); }
/// <summary> /// Get key for a localized control. /// </summary> /// <returns>The localized control id.</returns> public string GetKey() { return(LocalizedControl.GetKey(this.Dialog, this.Control)); }