diff options
Diffstat (limited to 'src/WixToolset.Core/Localizer.cs')
-rw-r--r-- | src/WixToolset.Core/Localizer.cs | 91 |
1 files changed, 46 insertions, 45 deletions
diff --git a/src/WixToolset.Core/Localizer.cs b/src/WixToolset.Core/Localizer.cs index 8265c026..d4f89e7a 100644 --- a/src/WixToolset.Core/Localizer.cs +++ b/src/WixToolset.Core/Localizer.cs | |||
@@ -9,6 +9,7 @@ namespace WixToolset.Core | |||
9 | using WixToolset.Data.Rows; | 9 | using WixToolset.Data.Rows; |
10 | using WixToolset.Core.Native; | 10 | using WixToolset.Core.Native; |
11 | using WixToolset.Extensibility; | 11 | using WixToolset.Extensibility; |
12 | using WixToolset.Extensibility.Services; | ||
12 | 13 | ||
13 | /// <summary> | 14 | /// <summary> |
14 | /// Parses localization files and localizes database values. | 15 | /// Parses localization files and localizes database values. |
@@ -24,7 +25,7 @@ namespace WixToolset.Core | |||
24 | /// <summary> | 25 | /// <summary> |
25 | /// Instantiate a new Localizer. | 26 | /// Instantiate a new Localizer. |
26 | /// </summary> | 27 | /// </summary> |
27 | public Localizer(IEnumerable<Localization> localizations) | 28 | public Localizer(IMessaging messaging, IEnumerable<Localization> localizations) |
28 | { | 29 | { |
29 | this.Codepage = -1; | 30 | this.Codepage = -1; |
30 | this.variables = new Dictionary<string, BindVariable>(); | 31 | this.variables = new Dictionary<string, BindVariable>(); |
@@ -39,7 +40,7 @@ namespace WixToolset.Core | |||
39 | 40 | ||
40 | foreach (var variable in localization.Variables) | 41 | foreach (var variable in localization.Variables) |
41 | { | 42 | { |
42 | Localizer.AddWixVariable(this.variables, variable); | 43 | Localizer.AddWixVariable(messaging, this.variables, variable); |
43 | } | 44 | } |
44 | 45 | ||
45 | foreach (KeyValuePair<string, LocalizedControl> localizedControl in localization.LocalizedControls) | 46 | foreach (KeyValuePair<string, LocalizedControl> localizedControl in localization.LocalizedControls) |
@@ -86,7 +87,7 @@ namespace WixToolset.Core | |||
86 | /// <param name="tableDefinitions">Collection containing TableDefinitions to use when loading the localization file.</param> | 87 | /// <param name="tableDefinitions">Collection containing TableDefinitions to use when loading the localization file.</param> |
87 | /// <param name="suppressSchema">Suppress xml schema validation while loading.</param> | 88 | /// <param name="suppressSchema">Suppress xml schema validation while loading.</param> |
88 | /// <returns>Returns the loaded localization file.</returns> | 89 | /// <returns>Returns the loaded localization file.</returns> |
89 | public static Localization ParseLocalizationFile(string path) | 90 | public static Localization ParseLocalizationFile(IMessaging messaging, string path) |
90 | { | 91 | { |
91 | XElement root = XDocument.Load(path).Root; | 92 | XElement root = XDocument.Load(path).Root; |
92 | Localization localization = null; | 93 | Localization localization = null; |
@@ -96,23 +97,23 @@ namespace WixToolset.Core | |||
96 | { | 97 | { |
97 | if (Localizer.WxlNamespace == root.Name.Namespace) | 98 | if (Localizer.WxlNamespace == root.Name.Namespace) |
98 | { | 99 | { |
99 | localization = ParseWixLocalizationElement(root); | 100 | localization = ParseWixLocalizationElement(messaging, root); |
100 | } | 101 | } |
101 | else // invalid or missing namespace | 102 | else // invalid or missing namespace |
102 | { | 103 | { |
103 | if (null == root.Name.Namespace) | 104 | if (null == root.Name.Namespace) |
104 | { | 105 | { |
105 | Messaging.Instance.OnMessage(WixErrors.InvalidWixXmlNamespace(sourceLineNumbers, Localizer.XmlElementName, Localizer.WxlNamespace.NamespaceName)); | 106 | messaging.Write(ErrorMessages.InvalidWixXmlNamespace(sourceLineNumbers, Localizer.XmlElementName, Localizer.WxlNamespace.NamespaceName)); |
106 | } | 107 | } |
107 | else | 108 | else |
108 | { | 109 | { |
109 | Messaging.Instance.OnMessage(WixErrors.InvalidWixXmlNamespace(sourceLineNumbers, Localizer.XmlElementName, root.Name.LocalName, Localizer.WxlNamespace.NamespaceName)); | 110 | messaging.Write(ErrorMessages.InvalidWixXmlNamespace(sourceLineNumbers, Localizer.XmlElementName, root.Name.LocalName, Localizer.WxlNamespace.NamespaceName)); |
110 | } | 111 | } |
111 | } | 112 | } |
112 | } | 113 | } |
113 | else | 114 | else |
114 | { | 115 | { |
115 | Messaging.Instance.OnMessage(WixErrors.InvalidDocumentElement(sourceLineNumbers, root.Name.LocalName, "localization", Localizer.XmlElementName)); | 116 | messaging.Write(ErrorMessages.InvalidDocumentElement(sourceLineNumbers, root.Name.LocalName, "localization", Localizer.XmlElementName)); |
116 | } | 117 | } |
117 | 118 | ||
118 | return localization; | 119 | return localization; |
@@ -123,7 +124,7 @@ namespace WixToolset.Core | |||
123 | /// </summary> | 124 | /// </summary> |
124 | /// <param name="variables">Dictionary of variable rows.</param> | 125 | /// <param name="variables">Dictionary of variable rows.</param> |
125 | /// <param name="wixVariableRow">Row to add to the variables dictionary.</param> | 126 | /// <param name="wixVariableRow">Row to add to the variables dictionary.</param> |
126 | private static void AddWixVariable(IDictionary<string, BindVariable> variables, BindVariable wixVariableRow) | 127 | private static void AddWixVariable(IMessaging messaging, IDictionary<string, BindVariable> variables, BindVariable wixVariableRow) |
127 | { | 128 | { |
128 | if (!variables.TryGetValue(wixVariableRow.Id, out var existingWixVariableRow) || (existingWixVariableRow.Overridable && !wixVariableRow.Overridable)) | 129 | if (!variables.TryGetValue(wixVariableRow.Id, out var existingWixVariableRow) || (existingWixVariableRow.Overridable && !wixVariableRow.Overridable)) |
129 | { | 130 | { |
@@ -131,7 +132,7 @@ namespace WixToolset.Core | |||
131 | } | 132 | } |
132 | else if (!wixVariableRow.Overridable) | 133 | else if (!wixVariableRow.Overridable) |
133 | { | 134 | { |
134 | Messaging.Instance.OnMessage(WixErrors.DuplicateLocalizationIdentifier(wixVariableRow.SourceLineNumbers, wixVariableRow.Id)); | 135 | messaging.Write(ErrorMessages.DuplicateLocalizationIdentifier(wixVariableRow.SourceLineNumbers, wixVariableRow.Id)); |
135 | } | 136 | } |
136 | } | 137 | } |
137 | 138 | ||
@@ -139,7 +140,7 @@ namespace WixToolset.Core | |||
139 | /// Parses the WixLocalization element. | 140 | /// Parses the WixLocalization element. |
140 | /// </summary> | 141 | /// </summary> |
141 | /// <param name="node">Element to parse.</param> | 142 | /// <param name="node">Element to parse.</param> |
142 | private static Localization ParseWixLocalizationElement(XElement node) | 143 | private static Localization ParseWixLocalizationElement(IMessaging messaging, XElement node) |
143 | { | 144 | { |
144 | int codepage = -1; | 145 | int codepage = -1; |
145 | string culture = null; | 146 | string culture = null; |
@@ -161,13 +162,13 @@ namespace WixToolset.Core | |||
161 | // do nothing; @Language is used for locutil which can't convert Culture to lcid | 162 | // do nothing; @Language is used for locutil which can't convert Culture to lcid |
162 | break; | 163 | break; |
163 | default: | 164 | default: |
164 | Common.UnexpectedAttribute(sourceLineNumbers, attrib); | 165 | Common.UnexpectedAttribute(messaging, sourceLineNumbers, attrib); |
165 | break; | 166 | break; |
166 | } | 167 | } |
167 | } | 168 | } |
168 | else | 169 | else |
169 | { | 170 | { |
170 | Common.UnexpectedAttribute(sourceLineNumbers, attrib); | 171 | Common.UnexpectedAttribute(messaging, sourceLineNumbers, attrib); |
171 | } | 172 | } |
172 | } | 173 | } |
173 | 174 | ||
@@ -181,32 +182,32 @@ namespace WixToolset.Core | |||
181 | switch (child.Name.LocalName) | 182 | switch (child.Name.LocalName) |
182 | { | 183 | { |
183 | case "String": | 184 | case "String": |
184 | Localizer.ParseString(child, variables); | 185 | Localizer.ParseString(messaging, child, variables); |
185 | break; | 186 | break; |
186 | 187 | ||
187 | case "UI": | 188 | case "UI": |
188 | Localizer.ParseUI(child, localizedControls); | 189 | Localizer.ParseUI(messaging, child, localizedControls); |
189 | break; | 190 | break; |
190 | 191 | ||
191 | default: | 192 | default: |
192 | Messaging.Instance.OnMessage(WixErrors.UnexpectedElement(sourceLineNumbers, node.Name.ToString(), child.Name.ToString())); | 193 | messaging.Write(ErrorMessages.UnexpectedElement(sourceLineNumbers, node.Name.ToString(), child.Name.ToString())); |
193 | break; | 194 | break; |
194 | } | 195 | } |
195 | } | 196 | } |
196 | else | 197 | else |
197 | { | 198 | { |
198 | Messaging.Instance.OnMessage(WixErrors.UnsupportedExtensionElement(sourceLineNumbers, node.Name.ToString(), child.Name.ToString())); | 199 | messaging.Write(ErrorMessages.UnsupportedExtensionElement(sourceLineNumbers, node.Name.ToString(), child.Name.ToString())); |
199 | } | 200 | } |
200 | } | 201 | } |
201 | 202 | ||
202 | return Messaging.Instance.EncounteredError ? null : new Localization(codepage, culture, variables, localizedControls); | 203 | return messaging.EncounteredError ? null : new Localization(codepage, culture, variables, localizedControls); |
203 | } | 204 | } |
204 | 205 | ||
205 | /// <summary> | 206 | /// <summary> |
206 | /// Parse a localization string into a WixVariableRow. | 207 | /// Parse a localization string into a WixVariableRow. |
207 | /// </summary> | 208 | /// </summary> |
208 | /// <param name="node">Element to parse.</param> | 209 | /// <param name="node">Element to parse.</param> |
209 | private static void ParseString(XElement node, IDictionary<string, BindVariable> variables) | 210 | private static void ParseString(IMessaging messaging, XElement node, IDictionary<string, BindVariable> variables) |
210 | { | 211 | { |
211 | string id = null; | 212 | string id = null; |
212 | bool overridable = false; | 213 | bool overridable = false; |
@@ -219,22 +220,22 @@ namespace WixToolset.Core | |||
219 | switch (attrib.Name.LocalName) | 220 | switch (attrib.Name.LocalName) |
220 | { | 221 | { |
221 | case "Id": | 222 | case "Id": |
222 | id = Common.GetAttributeIdentifierValue(sourceLineNumbers, attrib); | 223 | id = Common.GetAttributeIdentifierValue(messaging, sourceLineNumbers, attrib); |
223 | break; | 224 | break; |
224 | case "Overridable": | 225 | case "Overridable": |
225 | overridable = YesNoType.Yes == Common.GetAttributeYesNoValue(sourceLineNumbers, attrib); | 226 | overridable = YesNoType.Yes == Common.GetAttributeYesNoValue(messaging, sourceLineNumbers, attrib); |
226 | break; | 227 | break; |
227 | case "Localizable": | 228 | case "Localizable": |
228 | ; // do nothing | 229 | ; // do nothing |
229 | break; | 230 | break; |
230 | default: | 231 | default: |
231 | Messaging.Instance.OnMessage(WixErrors.UnexpectedAttribute(sourceLineNumbers, attrib.Parent.Name.ToString(), attrib.Name.ToString())); | 232 | messaging.Write(ErrorMessages.UnexpectedAttribute(sourceLineNumbers, attrib.Parent.Name.ToString(), attrib.Name.ToString())); |
232 | break; | 233 | break; |
233 | } | 234 | } |
234 | } | 235 | } |
235 | else | 236 | else |
236 | { | 237 | { |
237 | Messaging.Instance.OnMessage(WixErrors.UnsupportedExtensionAttribute(sourceLineNumbers, attrib.Parent.Name.ToString(), attrib.Name.ToString())); | 238 | messaging.Write(ErrorMessages.UnsupportedExtensionAttribute(sourceLineNumbers, attrib.Parent.Name.ToString(), attrib.Name.ToString())); |
238 | } | 239 | } |
239 | } | 240 | } |
240 | 241 | ||
@@ -242,14 +243,14 @@ namespace WixToolset.Core | |||
242 | 243 | ||
243 | if (null == id) | 244 | if (null == id) |
244 | { | 245 | { |
245 | Messaging.Instance.OnMessage(WixErrors.ExpectedAttribute(sourceLineNumbers, "String", "Id")); | 246 | messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, "String", "Id")); |
246 | } | 247 | } |
247 | else if (0 == id.Length) | 248 | else if (0 == id.Length) |
248 | { | 249 | { |
249 | Messaging.Instance.OnMessage(WixErrors.IllegalIdentifier(sourceLineNumbers, "String", "Id", 0)); | 250 | messaging.Write(ErrorMessages.IllegalIdentifier(sourceLineNumbers, "String", "Id", 0)); |
250 | } | 251 | } |
251 | 252 | ||
252 | if (!Messaging.Instance.EncounteredError) | 253 | if (!messaging.EncounteredError) |
253 | { | 254 | { |
254 | var variable = new BindVariable | 255 | var variable = new BindVariable |
255 | { | 256 | { |
@@ -259,7 +260,7 @@ namespace WixToolset.Core | |||
259 | Value = value, | 260 | Value = value, |
260 | }; | 261 | }; |
261 | 262 | ||
262 | Localizer.AddWixVariable(variables, variable); | 263 | Localizer.AddWixVariable(messaging, variables, variable); |
263 | } | 264 | } |
264 | } | 265 | } |
265 | 266 | ||
@@ -268,7 +269,7 @@ namespace WixToolset.Core | |||
268 | /// </summary> | 269 | /// </summary> |
269 | /// <param name="node">Element to parse.</param> | 270 | /// <param name="node">Element to parse.</param> |
270 | /// <param name="localizedControls">Dictionary of localized controls.</param> | 271 | /// <param name="localizedControls">Dictionary of localized controls.</param> |
271 | private static void ParseUI(XElement node, IDictionary<string, LocalizedControl> localizedControls) | 272 | private static void ParseUI(IMessaging messaging, XElement node, IDictionary<string, LocalizedControl> localizedControls) |
272 | { | 273 | { |
273 | string dialog = null; | 274 | string dialog = null; |
274 | string control = null; | 275 | string control = null; |
@@ -287,49 +288,49 @@ namespace WixToolset.Core | |||
287 | switch (attrib.Name.LocalName) | 288 | switch (attrib.Name.LocalName) |
288 | { | 289 | { |
289 | case "Dialog": | 290 | case "Dialog": |
290 | dialog = Common.GetAttributeIdentifierValue(sourceLineNumbers, attrib); | 291 | dialog = Common.GetAttributeIdentifierValue(messaging, sourceLineNumbers, attrib); |
291 | break; | 292 | break; |
292 | case "Control": | 293 | case "Control": |
293 | control = Common.GetAttributeIdentifierValue(sourceLineNumbers, attrib); | 294 | control = Common.GetAttributeIdentifierValue(messaging, sourceLineNumbers, attrib); |
294 | break; | 295 | break; |
295 | case "X": | 296 | case "X": |
296 | x = Common.GetAttributeIntegerValue(sourceLineNumbers, attrib, 0, short.MaxValue); | 297 | x = Common.GetAttributeIntegerValue(messaging, sourceLineNumbers, attrib, 0, short.MaxValue); |
297 | break; | 298 | break; |
298 | case "Y": | 299 | case "Y": |
299 | y = Common.GetAttributeIntegerValue(sourceLineNumbers, attrib, 0, short.MaxValue); | 300 | y = Common.GetAttributeIntegerValue(messaging, sourceLineNumbers, attrib, 0, short.MaxValue); |
300 | break; | 301 | break; |
301 | case "Width": | 302 | case "Width": |
302 | width = Common.GetAttributeIntegerValue(sourceLineNumbers, attrib, 0, short.MaxValue); | 303 | width = Common.GetAttributeIntegerValue(messaging, sourceLineNumbers, attrib, 0, short.MaxValue); |
303 | break; | 304 | break; |
304 | case "Height": | 305 | case "Height": |
305 | height = Common.GetAttributeIntegerValue(sourceLineNumbers, attrib, 0, short.MaxValue); | 306 | height = Common.GetAttributeIntegerValue(messaging, sourceLineNumbers, attrib, 0, short.MaxValue); |
306 | break; | 307 | break; |
307 | case "RightToLeft": | 308 | case "RightToLeft": |
308 | if (YesNoType.Yes == Common.GetAttributeYesNoValue(sourceLineNumbers, attrib)) | 309 | if (YesNoType.Yes == Common.GetAttributeYesNoValue(messaging, sourceLineNumbers, attrib)) |
309 | { | 310 | { |
310 | attribs |= MsiInterop.MsidbControlAttributesRTLRO; | 311 | attribs |= MsiInterop.MsidbControlAttributesRTLRO; |
311 | } | 312 | } |
312 | break; | 313 | break; |
313 | case "RightAligned": | 314 | case "RightAligned": |
314 | if (YesNoType.Yes == Common.GetAttributeYesNoValue(sourceLineNumbers, attrib)) | 315 | if (YesNoType.Yes == Common.GetAttributeYesNoValue(messaging, sourceLineNumbers, attrib)) |
315 | { | 316 | { |
316 | attribs |= MsiInterop.MsidbControlAttributesRightAligned; | 317 | attribs |= MsiInterop.MsidbControlAttributesRightAligned; |
317 | } | 318 | } |
318 | break; | 319 | break; |
319 | case "LeftScroll": | 320 | case "LeftScroll": |
320 | if (YesNoType.Yes == Common.GetAttributeYesNoValue(sourceLineNumbers, attrib)) | 321 | if (YesNoType.Yes == Common.GetAttributeYesNoValue(messaging, sourceLineNumbers, attrib)) |
321 | { | 322 | { |
322 | attribs |= MsiInterop.MsidbControlAttributesLeftScroll; | 323 | attribs |= MsiInterop.MsidbControlAttributesLeftScroll; |
323 | } | 324 | } |
324 | break; | 325 | break; |
325 | default: | 326 | default: |
326 | Common.UnexpectedAttribute(sourceLineNumbers, attrib); | 327 | Common.UnexpectedAttribute(messaging, sourceLineNumbers, attrib); |
327 | break; | 328 | break; |
328 | } | 329 | } |
329 | } | 330 | } |
330 | else | 331 | else |
331 | { | 332 | { |
332 | Common.UnexpectedAttribute(sourceLineNumbers, attrib); | 333 | Common.UnexpectedAttribute(messaging, sourceLineNumbers, attrib); |
333 | } | 334 | } |
334 | } | 335 | } |
335 | 336 | ||
@@ -339,24 +340,24 @@ namespace WixToolset.Core | |||
339 | { | 340 | { |
340 | if (MsiInterop.MsidbControlAttributesRTLRO == (attribs & MsiInterop.MsidbControlAttributesRTLRO)) | 341 | if (MsiInterop.MsidbControlAttributesRTLRO == (attribs & MsiInterop.MsidbControlAttributesRTLRO)) |
341 | { | 342 | { |
342 | Messaging.Instance.OnMessage(WixErrors.IllegalAttributeWithoutOtherAttributes(sourceLineNumbers, node.Name.ToString(), "RightToLeft", "Control")); | 343 | messaging.Write(ErrorMessages.IllegalAttributeWithoutOtherAttributes(sourceLineNumbers, node.Name.ToString(), "RightToLeft", "Control")); |
343 | } | 344 | } |
344 | else if (MsiInterop.MsidbControlAttributesRightAligned == (attribs & MsiInterop.MsidbControlAttributesRightAligned)) | 345 | else if (MsiInterop.MsidbControlAttributesRightAligned == (attribs & MsiInterop.MsidbControlAttributesRightAligned)) |
345 | { | 346 | { |
346 | Messaging.Instance.OnMessage(WixErrors.IllegalAttributeWithoutOtherAttributes(sourceLineNumbers, node.Name.ToString(), "RightAligned", "Control")); | 347 | messaging.Write(ErrorMessages.IllegalAttributeWithoutOtherAttributes(sourceLineNumbers, node.Name.ToString(), "RightAligned", "Control")); |
347 | } | 348 | } |
348 | else if (MsiInterop.MsidbControlAttributesLeftScroll == (attribs & MsiInterop.MsidbControlAttributesLeftScroll)) | 349 | else if (MsiInterop.MsidbControlAttributesLeftScroll == (attribs & MsiInterop.MsidbControlAttributesLeftScroll)) |
349 | { | 350 | { |
350 | Messaging.Instance.OnMessage(WixErrors.IllegalAttributeWithoutOtherAttributes(sourceLineNumbers, node.Name.ToString(), "LeftScroll", "Control")); | 351 | messaging.Write(ErrorMessages.IllegalAttributeWithoutOtherAttributes(sourceLineNumbers, node.Name.ToString(), "LeftScroll", "Control")); |
351 | } | 352 | } |
352 | } | 353 | } |
353 | 354 | ||
354 | if (String.IsNullOrEmpty(control) && String.IsNullOrEmpty(dialog)) | 355 | if (String.IsNullOrEmpty(control) && String.IsNullOrEmpty(dialog)) |
355 | { | 356 | { |
356 | Messaging.Instance.OnMessage(WixErrors.ExpectedAttributesWithOtherAttribute(sourceLineNumbers, node.Name.ToString(), "Dialog", "Control")); | 357 | messaging.Write(ErrorMessages.ExpectedAttributesWithOtherAttribute(sourceLineNumbers, node.Name.ToString(), "Dialog", "Control")); |
357 | } | 358 | } |
358 | 359 | ||
359 | if (!Messaging.Instance.EncounteredError) | 360 | if (!messaging.EncounteredError) |
360 | { | 361 | { |
361 | LocalizedControl localizedControl = new LocalizedControl(dialog, control, x, y, width, height, attribs, text); | 362 | LocalizedControl localizedControl = new LocalizedControl(dialog, control, x, y, width, height, attribs, text); |
362 | string key = localizedControl.GetKey(); | 363 | string key = localizedControl.GetKey(); |
@@ -364,11 +365,11 @@ namespace WixToolset.Core | |||
364 | { | 365 | { |
365 | if (String.IsNullOrEmpty(localizedControl.Control)) | 366 | if (String.IsNullOrEmpty(localizedControl.Control)) |
366 | { | 367 | { |
367 | Messaging.Instance.OnMessage(WixErrors.DuplicatedUiLocalization(sourceLineNumbers, localizedControl.Dialog)); | 368 | messaging.Write(ErrorMessages.DuplicatedUiLocalization(sourceLineNumbers, localizedControl.Dialog)); |
368 | } | 369 | } |
369 | else | 370 | else |
370 | { | 371 | { |
371 | Messaging.Instance.OnMessage(WixErrors.DuplicatedUiLocalization(sourceLineNumbers, localizedControl.Dialog, localizedControl.Control)); | 372 | messaging.Write(ErrorMessages.DuplicatedUiLocalization(sourceLineNumbers, localizedControl.Dialog, localizedControl.Control)); |
372 | } | 373 | } |
373 | } | 374 | } |
374 | else | 375 | else |