From 7be5d94529c8419b4bd5da4dcd838795622643cb Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 6 Dec 2023 15:30:16 -0800 Subject: Link localizations from WixExtensions the same as sections --- src/api/wix/WixToolset.Data/Localization.cs | 39 ++++++++++++++++++++-- .../wix/WixToolset.Data/LocalizationLocation.cs | 31 +++++++++++++++++ src/api/wix/WixToolset.Data/LocalizedControl.cs | 10 ++++-- .../WixToolset.Extensibility/BaseExtensionData.cs | 4 ++- .../wix/WixToolset.Extensibility/IExtensionData.cs | 6 ---- 5 files changed, 78 insertions(+), 12 deletions(-) create mode 100644 src/api/wix/WixToolset.Data/LocalizationLocation.cs (limited to 'src/api') diff --git a/src/api/wix/WixToolset.Data/Localization.cs b/src/api/wix/WixToolset.Data/Localization.cs index 70c096de..d7727f17 100644 --- a/src/api/wix/WixToolset.Data/Localization.cs +++ b/src/api/wix/WixToolset.Data/Localization.cs @@ -15,11 +15,20 @@ namespace WixToolset.Data private readonly Dictionary variables = new Dictionary(); private readonly Dictionary localizedControls = new Dictionary(); + /// + /// Instantiates a new localization object with default location. + /// + public Localization(int? codepage, int? summaryInformationCodepage, string culture, IDictionary variables, IDictionary localizedControls) : + this(LocalizationLocation.Source, codepage, summaryInformationCodepage, culture, variables, localizedControls) + { + } + /// /// Instantiates a new localization object. /// - public Localization(int? codepage, int? summaryInformationCodepage, string culture, IDictionary variables, IDictionary localizedControls) + public Localization(LocalizationLocation location, int? codepage, int? summaryInformationCodepage, string culture, IDictionary variables, IDictionary localizedControls) { + this.Location = location; this.Codepage = codepage; this.SummaryInformationCodepage = summaryInformationCodepage; this.Culture = culture?.ToLowerInvariant() ?? String.Empty; @@ -27,6 +36,11 @@ namespace WixToolset.Data this.localizedControls = new Dictionary(localizedControls); } + /// + /// Gets the location the localization came from. + /// + public LocalizationLocation Location { get; private set; } + /// /// Gets the codepage. /// @@ -57,9 +71,27 @@ namespace WixToolset.Data /// The localized controls. public ICollection> LocalizedControls => this.localizedControls; + /// + /// Updates the location, if the location is a higher state than the current state. + /// + /// Location to update to. + /// This localization object. + public Localization UpdateLocation(LocalizationLocation location) + { + if (this.Location < location) + { + this.Location = location; + } + + return this; + } + internal JsonObject Serialize() { - var jsonObject = new JsonObject(); + var jsonObject = new JsonObject() + { + { "location", this.Location.ToString().ToLowerInvariant() } + }; if (this.Codepage.HasValue) { @@ -108,6 +140,7 @@ namespace WixToolset.Data internal static Localization Deserialize(JsonObject jsonObject) { + var location = jsonObject.GetEnumOrDefault("location", LocalizationLocation.Source); var codepage = jsonObject.GetValueOrDefault("codepage", null); var summaryCodepage = jsonObject.GetValueOrDefault("summaryCodepage", null); var culture = jsonObject.GetValueOrDefault("culture"); @@ -131,7 +164,7 @@ namespace WixToolset.Data } } - return new Localization(codepage, summaryCodepage, culture, variables, controls); + return new Localization(location, codepage, summaryCodepage, culture, variables, controls); } } } diff --git a/src/api/wix/WixToolset.Data/LocalizationLocation.cs b/src/api/wix/WixToolset.Data/LocalizationLocation.cs new file mode 100644 index 00000000..773c4d9f --- /dev/null +++ b/src/api/wix/WixToolset.Data/LocalizationLocation.cs @@ -0,0 +1,31 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace WixToolset.Data +{ + /// + /// Location where the localization was loaded. + /// + public enum LocalizationLocation + { + /// + /// Localization loaded from .wxl source file. + /// + Source, + + /// + /// Localization loaded from .wixlib library. + /// + Library, + + /// + /// Localization loaded from .wixlib library within .wixext WixExtension. + /// + Extension, + + /// + /// Localization placed in .wixext WixExtension as the default culture localization for the + /// WixExtension. + /// + ExtensionDefaultCulture + } +} diff --git a/src/api/wix/WixToolset.Data/LocalizedControl.cs b/src/api/wix/WixToolset.Data/LocalizedControl.cs index 1252842b..9f59ce46 100644 --- a/src/api/wix/WixToolset.Data/LocalizedControl.cs +++ b/src/api/wix/WixToolset.Data/LocalizedControl.cs @@ -45,7 +45,10 @@ namespace WixToolset.Data /// Get key for a localized control. /// /// The localized control id. - public string GetKey() => LocalizedControl.GetKey(this.Dialog, this.Control); + public string GetKey() + { + return LocalizedControl.GetKey(this.Dialog, this.Control); + } /// /// Get key for a localized control. @@ -53,7 +56,10 @@ namespace WixToolset.Data /// The optional id of the control's dialog. /// The id of the control. /// The localized control id. - public static string GetKey(string dialog, string control) => String.Concat(dialog, "/", control); + public static string GetKey(string dialog, string control) + { + return String.Concat(dialog, "/", control); + } internal JsonObject Serialize() { diff --git a/src/api/wix/WixToolset.Extensibility/BaseExtensionData.cs b/src/api/wix/WixToolset.Extensibility/BaseExtensionData.cs index e4a10fd9..291b1014 100644 --- a/src/api/wix/WixToolset.Extensibility/BaseExtensionData.cs +++ b/src/api/wix/WixToolset.Extensibility/BaseExtensionData.cs @@ -2,6 +2,7 @@ namespace WixToolset.Extensibility { + using System; using WixToolset.Data; /// @@ -10,8 +11,9 @@ namespace WixToolset.Extensibility public abstract class BaseExtensionData : IExtensionData { /// - /// See + /// Obsolete in WiX v5. Use the WixLocalization/@ExtensionDefaultCulture attribute in the wxl file instead. /// + [Obsolete("Set the ExtensionDefaultCulture attribute in the WixLocalization source file instead.")] public virtual string DefaultCulture => null; /// diff --git a/src/api/wix/WixToolset.Extensibility/IExtensionData.cs b/src/api/wix/WixToolset.Extensibility/IExtensionData.cs index 823e2beb..e6565f4a 100644 --- a/src/api/wix/WixToolset.Extensibility/IExtensionData.cs +++ b/src/api/wix/WixToolset.Extensibility/IExtensionData.cs @@ -9,12 +9,6 @@ namespace WixToolset.Extensibility /// public interface IExtensionData { - /// - /// Gets the optional default culture. - /// - /// The optional default culture. - string DefaultCulture { get; } - /// /// /// -- cgit v1.2.3-55-g6feb