diff options
Diffstat (limited to 'src/WixToolset.Core/Localizer.cs')
-rw-r--r-- | src/WixToolset.Core/Localizer.cs | 53 |
1 files changed, 24 insertions, 29 deletions
diff --git a/src/WixToolset.Core/Localizer.cs b/src/WixToolset.Core/Localizer.cs index 3c299896..63ead24a 100644 --- a/src/WixToolset.Core/Localizer.cs +++ b/src/WixToolset.Core/Localizer.cs | |||
@@ -23,11 +23,32 @@ namespace WixToolset | |||
23 | /// <summary> | 23 | /// <summary> |
24 | /// Instantiate a new Localizer. | 24 | /// Instantiate a new Localizer. |
25 | /// </summary> | 25 | /// </summary> |
26 | public Localizer() | 26 | public Localizer(IEnumerable<Localization> localizations) |
27 | { | 27 | { |
28 | this.Codepage = -1; | 28 | this.Codepage = -1; |
29 | this.variables = new Dictionary<string,WixVariableRow>(); | 29 | this.variables = new Dictionary<string, WixVariableRow>(); |
30 | this.localizedControls = new Dictionary<string, LocalizedControl>(); | 30 | this.localizedControls = new Dictionary<string, LocalizedControl>(); |
31 | |||
32 | foreach (var localization in localizations) | ||
33 | { | ||
34 | if (-1 == this.Codepage) | ||
35 | { | ||
36 | this.Codepage = localization.Codepage; | ||
37 | } | ||
38 | |||
39 | foreach (WixVariableRow wixVariableRow in localization.Variables) | ||
40 | { | ||
41 | Localizer.AddWixVariable(this.variables, wixVariableRow); | ||
42 | } | ||
43 | |||
44 | foreach (KeyValuePair<string, LocalizedControl> localizedControl in localization.LocalizedControls) | ||
45 | { | ||
46 | if (!this.localizedControls.ContainsKey(localizedControl.Key)) | ||
47 | { | ||
48 | this.localizedControls.Add(localizedControl.Key, localizedControl.Value); | ||
49 | } | ||
50 | } | ||
51 | } | ||
31 | } | 52 | } |
32 | 53 | ||
33 | /// <summary> | 54 | /// <summary> |
@@ -76,39 +97,13 @@ namespace WixToolset | |||
76 | } | 97 | } |
77 | 98 | ||
78 | /// <summary> | 99 | /// <summary> |
79 | /// Add a localization file. | ||
80 | /// </summary> | ||
81 | /// <param name="localization">The localization file to add.</param> | ||
82 | public void AddLocalization(Localization localization) | ||
83 | { | ||
84 | if (-1 == this.Codepage) | ||
85 | { | ||
86 | this.Codepage = localization.Codepage; | ||
87 | } | ||
88 | |||
89 | foreach (WixVariableRow wixVariableRow in localization.Variables) | ||
90 | { | ||
91 | Localizer.AddWixVariable(this.variables, wixVariableRow); | ||
92 | } | ||
93 | |||
94 | foreach (KeyValuePair<string, LocalizedControl> localizedControl in localization.LocalizedControls) | ||
95 | { | ||
96 | if (!this.localizedControls.ContainsKey(localizedControl.Key)) | ||
97 | { | ||
98 | this.localizedControls.Add(localizedControl.Key, localizedControl.Value); | ||
99 | } | ||
100 | } | ||
101 | } | ||
102 | |||
103 | /// <summary> | ||
104 | /// Get a localized data value. | 100 | /// Get a localized data value. |
105 | /// </summary> | 101 | /// </summary> |
106 | /// <param name="id">The name of the localization variable.</param> | 102 | /// <param name="id">The name of the localization variable.</param> |
107 | /// <returns>The localized data value or null if it wasn't found.</returns> | 103 | /// <returns>The localized data value or null if it wasn't found.</returns> |
108 | public string GetLocalizedValue(string id) | 104 | public string GetLocalizedValue(string id) |
109 | { | 105 | { |
110 | WixVariableRow wixVariableRow; | 106 | return this.variables.TryGetValue(id, out var wixVariableRow) ? wixVariableRow.Value : null; |
111 | return this.variables.TryGetValue(id, out wixVariableRow) ? wixVariableRow.Value : null; | ||
112 | } | 107 | } |
113 | 108 | ||
114 | /// <summary> | 109 | /// <summary> |