diff options
| author | Rob Mensching <rob@firegiant.com> | 2017-10-14 16:12:07 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2017-10-14 16:12:07 -0700 |
| commit | dbde9e7104b907bbbaea17e21247d8cafc8b3a4c (patch) | |
| tree | 0f5fbbb6fe12c6b2e5e622a0e18ce4c5b4eb2b96 /src/WixToolset.Core/Localizer.cs | |
| parent | fbf986eb97f68396797a89fc7d40dec07b775440 (diff) | |
| download | wix-dbde9e7104b907bbbaea17e21247d8cafc8b3a4c.tar.gz wix-dbde9e7104b907bbbaea17e21247d8cafc8b3a4c.tar.bz2 wix-dbde9e7104b907bbbaea17e21247d8cafc8b3a4c.zip | |
Massive refactoring to introduce the concept of IBackend
Diffstat (limited to 'src/WixToolset.Core/Localizer.cs')
| -rw-r--r-- | src/WixToolset.Core/Localizer.cs | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/src/WixToolset.Core/Localizer.cs b/src/WixToolset.Core/Localizer.cs index 63ead24a..72d0955b 100644 --- a/src/WixToolset.Core/Localizer.cs +++ b/src/WixToolset.Core/Localizer.cs | |||
| @@ -8,11 +8,12 @@ namespace WixToolset | |||
| 8 | using WixToolset.Data; | 8 | using WixToolset.Data; |
| 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 | 12 | ||
| 12 | /// <summary> | 13 | /// <summary> |
| 13 | /// Parses localization files and localizes database values. | 14 | /// Parses localization files and localizes database values. |
| 14 | /// </summary> | 15 | /// </summary> |
| 15 | public sealed class Localizer | 16 | public sealed class Localizer : ILocalizer |
| 16 | { | 17 | { |
| 17 | public static readonly XNamespace WxlNamespace = "http://wixtoolset.org/schemas/v4/wxl"; | 18 | public static readonly XNamespace WxlNamespace = "http://wixtoolset.org/schemas/v4/wxl"; |
| 18 | private static string XmlElementName = "WixLocalization"; | 19 | private static string XmlElementName = "WixLocalization"; |
| @@ -55,7 +56,28 @@ namespace WixToolset | |||
| 55 | /// Gets the codepage. | 56 | /// Gets the codepage. |
| 56 | /// </summary> | 57 | /// </summary> |
| 57 | /// <value>The codepage.</value> | 58 | /// <value>The codepage.</value> |
| 58 | public int Codepage { get; private set; } | 59 | public int Codepage { get; } |
| 60 | |||
| 61 | /// <summary> | ||
| 62 | /// Get a localized data value. | ||
| 63 | /// </summary> | ||
| 64 | /// <param name="id">The name of the localization variable.</param> | ||
| 65 | /// <returns>The localized data value or null if it wasn't found.</returns> | ||
| 66 | public string GetLocalizedValue(string id) | ||
| 67 | { | ||
| 68 | return this.variables.TryGetValue(id, out var wixVariableRow) ? wixVariableRow.Value : null; | ||
| 69 | } | ||
| 70 | |||
| 71 | /// <summary> | ||
| 72 | /// Get a localized control. | ||
| 73 | /// </summary> | ||
| 74 | /// <param name="dialog">The optional id of the control's dialog.</param> | ||
| 75 | /// <param name="control">The id of the control.</param> | ||
| 76 | /// <returns>The localized control or null if it wasn't found.</returns> | ||
| 77 | public LocalizedControl GetLocalizedControl(string dialog, string control) | ||
| 78 | { | ||
| 79 | return this.localizedControls.TryGetValue(LocalizedControl.GetKey(dialog, control), out var localizedControl) ? localizedControl : null; | ||
| 80 | } | ||
| 59 | 81 | ||
| 60 | /// <summary> | 82 | /// <summary> |
| 61 | /// Loads a localization file from a path on disk. | 83 | /// Loads a localization file from a path on disk. |
| @@ -97,36 +119,13 @@ namespace WixToolset | |||
| 97 | } | 119 | } |
| 98 | 120 | ||
| 99 | /// <summary> | 121 | /// <summary> |
| 100 | /// Get a localized data value. | ||
| 101 | /// </summary> | ||
| 102 | /// <param name="id">The name of the localization variable.</param> | ||
| 103 | /// <returns>The localized data value or null if it wasn't found.</returns> | ||
| 104 | public string GetLocalizedValue(string id) | ||
| 105 | { | ||
| 106 | return this.variables.TryGetValue(id, out var wixVariableRow) ? wixVariableRow.Value : null; | ||
| 107 | } | ||
| 108 | |||
| 109 | /// <summary> | ||
| 110 | /// Get a localized control. | ||
| 111 | /// </summary> | ||
| 112 | /// <param name="dialog">The optional id of the control's dialog.</param> | ||
| 113 | /// <param name="control">The id of the control.</param> | ||
| 114 | /// <returns>The localized control or null if it wasn't found.</returns> | ||
| 115 | public LocalizedControl GetLocalizedControl(string dialog, string control) | ||
| 116 | { | ||
| 117 | LocalizedControl localizedControl; | ||
| 118 | return this.localizedControls.TryGetValue(LocalizedControl.GetKey(dialog, control), out localizedControl) ? localizedControl : null; | ||
| 119 | } | ||
| 120 | |||
| 121 | /// <summary> | ||
| 122 | /// Adds a WixVariableRow to a dictionary while performing the expected override checks. | 122 | /// Adds a WixVariableRow to a dictionary while performing the expected override checks. |
| 123 | /// </summary> | 123 | /// </summary> |
| 124 | /// <param name="variables">Dictionary of variable rows.</param> | 124 | /// <param name="variables">Dictionary of variable rows.</param> |
| 125 | /// <param name="wixVariableRow">Row to add to the variables dictionary.</param> | 125 | /// <param name="wixVariableRow">Row to add to the variables dictionary.</param> |
| 126 | private static void AddWixVariable(IDictionary<string, WixVariableRow> variables, WixVariableRow wixVariableRow) | 126 | private static void AddWixVariable(IDictionary<string, WixVariableRow> variables, WixVariableRow wixVariableRow) |
| 127 | { | 127 | { |
| 128 | WixVariableRow existingWixVariableRow; | 128 | if (!variables.TryGetValue(wixVariableRow.Id, out var existingWixVariableRow) || (existingWixVariableRow.Overridable && !wixVariableRow.Overridable)) |
| 129 | if (!variables.TryGetValue(wixVariableRow.Id, out existingWixVariableRow) || (existingWixVariableRow.Overridable && !wixVariableRow.Overridable)) | ||
| 130 | { | 129 | { |
| 131 | variables[wixVariableRow.Id] = wixVariableRow; | 130 | variables[wixVariableRow.Id] = wixVariableRow; |
| 132 | } | 131 | } |
