diff options
| author | Rob Mensching <rob@firegiant.com> | 2017-12-30 01:31:32 -0800 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2017-12-30 01:31:32 -0800 |
| commit | 7b013ac66a36e0f73d480ef28771a65f64b57e19 (patch) | |
| tree | 4a2996a1a539337ae27f3b9dfc692cf6052b897c /src/WixToolset.Data/Localization.cs | |
| parent | bcfae2a06a3a6c7e778b615e765b5a9efe847c0c (diff) | |
| download | wix-7b013ac66a36e0f73d480ef28771a65f64b57e19.tar.gz wix-7b013ac66a36e0f73d480ef28771a65f64b57e19.tar.bz2 wix-7b013ac66a36e0f73d480ef28771a65f64b57e19.zip | |
Support serializing localization information in Intermediates
Diffstat (limited to 'src/WixToolset.Data/Localization.cs')
| -rw-r--r-- | src/WixToolset.Data/Localization.cs | 72 |
1 files changed, 71 insertions, 1 deletions
diff --git a/src/WixToolset.Data/Localization.cs b/src/WixToolset.Data/Localization.cs index 10eff2e1..4ddef77b 100644 --- a/src/WixToolset.Data/Localization.cs +++ b/src/WixToolset.Data/Localization.cs | |||
| @@ -7,8 +7,9 @@ namespace WixToolset.Data | |||
| 7 | using System.Diagnostics; | 7 | using System.Diagnostics; |
| 8 | using System.Globalization; | 8 | using System.Globalization; |
| 9 | using System.Xml; | 9 | using System.Xml; |
| 10 | using SimpleJson; | ||
| 10 | using WixToolset.Data.Msi; | 11 | using WixToolset.Data.Msi; |
| 11 | using WixToolset.Data.Rows; | 12 | using WixToolset.Data.Bind; |
| 12 | 13 | ||
| 13 | /// <summary> | 14 | /// <summary> |
| 14 | /// Object that represents a localization file. | 15 | /// Object that represents a localization file. |
| @@ -74,6 +75,75 @@ namespace WixToolset.Data | |||
| 74 | } | 75 | } |
| 75 | } | 76 | } |
| 76 | 77 | ||
| 78 | internal JsonObject Serialize() | ||
| 79 | { | ||
| 80 | var jsonObject = new JsonObject | ||
| 81 | { | ||
| 82 | { "codepage", this.Codepage }, | ||
| 83 | }; | ||
| 84 | |||
| 85 | jsonObject.AddIsNotNullOrEmpty("culture", this.Culture); | ||
| 86 | |||
| 87 | // Serialize bind variables. | ||
| 88 | if (this.Variables.Count > 0) | ||
| 89 | { | ||
| 90 | var variablesJson = new JsonArray(this.Variables.Count); | ||
| 91 | |||
| 92 | foreach (var variable in this.Variables) | ||
| 93 | { | ||
| 94 | var variableJson = variable.Serialize(); | ||
| 95 | |||
| 96 | variablesJson.Add(variableJson); | ||
| 97 | } | ||
| 98 | |||
| 99 | jsonObject.Add("variables", variablesJson); | ||
| 100 | } | ||
| 101 | |||
| 102 | // Serialize localized control. | ||
| 103 | if (this.LocalizedControls.Count > 0) | ||
| 104 | { | ||
| 105 | var controlsJson = new JsonObject(); | ||
| 106 | |||
| 107 | foreach (var controlWithKey in this.LocalizedControls) | ||
| 108 | { | ||
| 109 | var controlJson = controlWithKey.Value.Serialize(); | ||
| 110 | |||
| 111 | controlsJson.Add(controlWithKey.Key, controlJson); | ||
| 112 | } | ||
| 113 | |||
| 114 | jsonObject.Add("controls", controlsJson); | ||
| 115 | } | ||
| 116 | |||
| 117 | return jsonObject; | ||
| 118 | } | ||
| 119 | |||
| 120 | internal static Localization Deserialize(JsonObject jsonObject) | ||
| 121 | { | ||
| 122 | var codepage = jsonObject.GetValueOrDefault("codepage", 0); | ||
| 123 | var culture = jsonObject.GetValueOrDefault<string>("culture"); | ||
| 124 | |||
| 125 | var variables = new Dictionary<string, BindVariable>(); | ||
| 126 | var variablesJson = jsonObject.GetValueOrDefault("variables", new JsonArray()); | ||
| 127 | foreach (JsonObject variableJson in variablesJson) | ||
| 128 | { | ||
| 129 | var bindPath = BindVariable.Deserialize(variableJson); | ||
| 130 | variables.Add(bindPath.Id, bindPath); | ||
| 131 | } | ||
| 132 | |||
| 133 | var controls = new Dictionary<string, LocalizedControl>(); | ||
| 134 | var controlsJson = jsonObject.GetValueOrDefault<JsonObject>("controls"); | ||
| 135 | if (controlsJson != null) | ||
| 136 | { | ||
| 137 | foreach (var controlJsonWithKey in controlsJson) | ||
| 138 | { | ||
| 139 | var control = LocalizedControl.Deserialize((JsonObject)controlJsonWithKey.Value); | ||
| 140 | controls.Add(controlJsonWithKey.Key, control); | ||
| 141 | } | ||
| 142 | } | ||
| 143 | |||
| 144 | return new Localization(codepage, culture, variables, controls); | ||
| 145 | } | ||
| 146 | |||
| 77 | /// <summary> | 147 | /// <summary> |
| 78 | /// Loads a localization file from a stream. | 148 | /// Loads a localization file from a stream. |
| 79 | /// </summary> | 149 | /// </summary> |
