Skip to content

Commit

Permalink
Link localizations from WixExtensions the same as sections
Browse files Browse the repository at this point in the history
  • Loading branch information
robmen committed Dec 16, 2023
1 parent 1bdcbeb commit 7be5d94
Show file tree
Hide file tree
Showing 41 changed files with 237 additions and 121 deletions.
39 changes: 36 additions & 3 deletions src/api/wix/WixToolset.Data/Localization.cs
Expand Up @@ -15,18 +15,32 @@ public sealed class Localization
private readonly Dictionary<string, BindVariable> variables = new Dictionary<string, BindVariable>();
private readonly Dictionary<string, LocalizedControl> localizedControls = new Dictionary<string, LocalizedControl>();

/// <summary>
/// Instantiates a new localization object with default location.
/// </summary>
public Localization(int? codepage, int? summaryInformationCodepage, string culture, IDictionary<string, BindVariable> variables, IDictionary<string, LocalizedControl> localizedControls) :
this(LocalizationLocation.Source, codepage, summaryInformationCodepage, culture, variables, localizedControls)
{
}

/// <summary>
/// Instantiates a new localization object.
/// </summary>
public Localization(int? codepage, int? summaryInformationCodepage, string culture, IDictionary<string, BindVariable> variables, IDictionary<string, LocalizedControl> localizedControls)
public Localization(LocalizationLocation location, int? codepage, int? summaryInformationCodepage, string culture, IDictionary<string, BindVariable> variables, IDictionary<string, LocalizedControl> localizedControls)
{
this.Location = location;
this.Codepage = codepage;
this.SummaryInformationCodepage = summaryInformationCodepage;
this.Culture = culture?.ToLowerInvariant() ?? String.Empty;
this.variables = new Dictionary<string, BindVariable>(variables);
this.localizedControls = new Dictionary<string, LocalizedControl>(localizedControls);
}

/// <summary>
/// Gets the location the localization came from.
/// </summary>
public LocalizationLocation Location { get; private set; }

/// <summary>
/// Gets the codepage.
/// </summary>
Expand Down Expand Up @@ -57,9 +71,27 @@ public Localization(int? codepage, int? summaryInformationCodepage, string cultu
/// <value>The localized controls.</value>
public ICollection<KeyValuePair<string, LocalizedControl>> LocalizedControls => this.localizedControls;

/// <summary>
/// Updates the location, if the location is a higher state than the current state.
/// </summary>
/// <param name="location">Location to update to.</param>
/// <returns>This localization object.</returns>
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)
{
Expand Down Expand Up @@ -108,6 +140,7 @@ internal JsonObject Serialize()

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<string>("culture");
Expand All @@ -131,7 +164,7 @@ internal static Localization Deserialize(JsonObject jsonObject)
}
}

return new Localization(codepage, summaryCodepage, culture, variables, controls);
return new Localization(location, codepage, summaryCodepage, culture, variables, controls);
}
}
}
31 changes: 31 additions & 0 deletions 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
{
/// <summary>
/// Location where the localization was loaded.
/// </summary>
public enum LocalizationLocation
{
/// <summary>
/// Localization loaded from .wxl source file.
/// </summary>
Source,

/// <summary>
/// Localization loaded from .wixlib library.
/// </summary>
Library,

/// <summary>
/// Localization loaded from .wixlib library within .wixext WixExtension.
/// </summary>
Extension,

/// <summary>
/// Localization placed in .wixext WixExtension as the default culture localization for the
/// WixExtension.
/// </summary>
ExtensionDefaultCulture
}
}
10 changes: 8 additions & 2 deletions src/api/wix/WixToolset.Data/LocalizedControl.cs
Expand Up @@ -45,15 +45,21 @@ public LocalizedControl(string dialog, string control, int x, int y, int width,
/// Get key for a localized control.
/// </summary>
/// <returns>The localized control id.</returns>
public string GetKey() => LocalizedControl.GetKey(this.Dialog, this.Control);
public string GetKey()
{
return LocalizedControl.GetKey(this.Dialog, this.Control);
}

/// <summary>
/// Get key for a localized control.
/// </summary>
/// <param name="dialog">The optional id of the control's dialog.</param>
/// <param name="control">The id of the control.</param>
/// <returns>The localized control id.</returns>
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()
{
Expand Down
4 changes: 3 additions & 1 deletion src/api/wix/WixToolset.Extensibility/BaseExtensionData.cs
Expand Up @@ -2,6 +2,7 @@

namespace WixToolset.Extensibility
{
using System;
using WixToolset.Data;

/// <summary>
Expand All @@ -10,8 +11,9 @@ namespace WixToolset.Extensibility
public abstract class BaseExtensionData : IExtensionData
{
/// <summary>
/// See <see cref="IExtensionData.DefaultCulture"/>
/// Obsolete in WiX v5. Use the WixLocalization/@ExtensionDefaultCulture attribute in the wxl file instead.
/// </summary>
[Obsolete("Set the ExtensionDefaultCulture attribute in the WixLocalization source file instead.")]
public virtual string DefaultCulture => null;

/// <summary>
Expand Down
6 changes: 0 additions & 6 deletions src/api/wix/WixToolset.Extensibility/IExtensionData.cs
Expand Up @@ -9,12 +9,6 @@ namespace WixToolset.Extensibility
/// </summary>
public interface IExtensionData
{
/// <summary>
/// Gets the optional default culture.
/// </summary>
/// <value>The optional default culture.</value>
string DefaultCulture { get; }

/// <summary>
///
/// </summary>
Expand Down
6 changes: 0 additions & 6 deletions src/ext/Bal/wixext/BalExtensionData.cs
Expand Up @@ -10,12 +10,6 @@ namespace WixToolset.Bal
/// </summary>
public sealed class BalExtensionData : BaseExtensionData
{
/// <summary>
/// Gets the default culture.
/// </summary>
/// <value>The default culture.</value>
public override string DefaultCulture => "en-US";

public override bool TryGetSymbolDefinitionByName(string name, out IntermediateSymbolDefinition symbolDefinition)
{
symbolDefinition = BalSymbolDefinitions.ByName(name);
Expand Down
6 changes: 0 additions & 6 deletions src/ext/ComPlus/wixext/ComPlusExtensionData.cs
Expand Up @@ -10,12 +10,6 @@ namespace WixToolset.ComPlus
/// </summary>
public sealed class ComPlusExtensionData : BaseExtensionData
{
/// <summary>
/// Gets the default culture.
/// </summary>
/// <value>The default culture.</value>
public override string DefaultCulture => "en-US";

public override bool TryGetSymbolDefinitionByName(string name, out IntermediateSymbolDefinition symbolDefinition)
{
symbolDefinition = ComPlusSymbolDefinitions.ByName(name);
Expand Down
2 changes: 1 addition & 1 deletion src/ext/ComPlus/wixlib/en-us.wxl
@@ -1,7 +1,7 @@
<!-- 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. -->


<WixLocalization Culture="en-us" xmlns="http://wixtoolset.org/schemas/v4/wxl">
<WixLocalization Culture="en-us" ExtensionDefaultCulture="yes" xmlns="http://wixtoolset.org/schemas/v4/wxl">
<String Id="msierrComPlusCannotConnect" Overridable="yes" Value="Cannot connect to the COM+ admin catalog. ([2] [3] [4] [5])" />
<String Id="msierrComPlusPartitionReadFailed" Overridable="yes" Value="Failed to read COM+ partitions. ([2] [3] [4] [5])" />
<String Id="msierrComPlusPartitionRoleReadFailed" Overridable="yes" Value="Failed to read COM+ partition roles. ([2] [3] [4] [5])" />
Expand Down
6 changes: 0 additions & 6 deletions src/ext/Dependency/wixext/DependencyExtensionData.cs
Expand Up @@ -10,12 +10,6 @@ namespace WixToolset.Dependency
/// </summary>
public sealed class DependencyExtensionData : BaseExtensionData
{
/// <summary>
/// Gets the default culture.
/// </summary>
/// <value>The default culture.</value>
public override string DefaultCulture => "en-US";

/// <summary>
/// Gets the contained .wixlib content.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/ext/Dependency/wixlib/en-us.wxl
@@ -1,7 +1,7 @@
<!-- 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. -->


<WixLocalization Culture="en-US" xmlns="http://wixtoolset.org/schemas/v4/wxl">
<WixLocalization Culture="en-US" ExtensionDefaultCulture="yes" xmlns="http://wixtoolset.org/schemas/v4/wxl">
<String Id="msierrDependencyMissingDependencies" Overridable="yes" Value="If you continue with this install, the product may not work properly because [2] or more dependencies are missing. Do you want to continue with this install anyway?" />
<String Id="msierrDependencyHasDependents" Overridable="yes" Value="If you continue with this uninstall, [2] or more products may stop working properly. Do you want to continue with this uninstall anyway?" />
</WixLocalization>
6 changes: 0 additions & 6 deletions src/ext/DirectX/wixext/DirectXExtensionData.cs
Expand Up @@ -10,12 +10,6 @@ namespace WixToolset.DirectX
/// </summary>
public sealed class DirectXExtensionData : BaseExtensionData
{
/// <summary>
/// Gets the default culture.
/// </summary>
/// <value>The default culture.</value>
public override string DefaultCulture => "en-US";

public override Intermediate GetLibrary(ISymbolDefinitionCreator symbolDefinitions)
{
return Intermediate.Load(typeof(DirectXExtensionData).Assembly, "WixToolset.DirectX.directx.wixlib", symbolDefinitions);
Expand Down
2 changes: 0 additions & 2 deletions src/ext/Firewall/wixext/FirewallExtensionData.cs
Expand Up @@ -7,8 +7,6 @@ namespace WixToolset.Firewall

public sealed class FirewallExtensionData : BaseExtensionData
{
public override string DefaultCulture => "en-US";

public override bool TryGetSymbolDefinitionByName(string name, out IntermediateSymbolDefinition symbolDefinition)
{
symbolDefinition = FirewallSymbolDefinitions.ByName(name);
Expand Down
2 changes: 1 addition & 1 deletion src/ext/Firewall/wixlib/en-us.wxl
@@ -1,7 +1,7 @@
<!-- 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. -->


<WixLocalization Culture="en-us" xmlns="http://wixtoolset.org/schemas/v4/wxl">
<WixLocalization Culture="en-us" ExtensionDefaultCulture="yes" xmlns="http://wixtoolset.org/schemas/v4/wxl">
<String Id="msierrFirewallCannotConnect" Overridable="yes" Value="Cannot connect to Windows Firewall. ([2] [3] [4] [5])" />

<String Id="WixSchedFirewallExceptionsInstall" Overridable="yes" Value="Configuring Windows Firewall" />
Expand Down
6 changes: 0 additions & 6 deletions src/ext/Http/wixext/HttpExtensionData.cs
Expand Up @@ -10,12 +10,6 @@ namespace WixToolset.Http
/// </summary>
public sealed class HttpExtensionData : BaseExtensionData
{
/// <summary>
/// Gets the default culture.
/// </summary>
/// <value>The default culture.</value>
public override string DefaultCulture => "en-US";

public override bool TryGetSymbolDefinitionByName(string name, out IntermediateSymbolDefinition symbolDefinition)
{
symbolDefinition = HttpSymbolDefinitions.ByName(name);
Expand Down
2 changes: 1 addition & 1 deletion src/ext/Http/wixlib/en-us.wxl
@@ -1,6 +1,6 @@
<!-- 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. -->

<WixLocalization Culture="en-us" xmlns="http://wixtoolset.org/schemas/v4/wxl">
<WixLocalization Culture="en-us" ExtensionDefaultCulture="yes" xmlns="http://wixtoolset.org/schemas/v4/wxl">
<String Id="WixSchedHttpUrlReservationsInstall" Overridable="yes" Value="Preparing to configure Windows HTTP Server" />
<String Id="WixSchedHttpUrlReservationsUninstall" Overridable="yes" Value="Preparing to configure Windows HTTP Server" />
<String Id="WixRollbackHttpUrlReservationsInstall" Overridable="yes" Value="Rolling back Windows HTTP Server configuration" />
Expand Down
6 changes: 0 additions & 6 deletions src/ext/Iis/wixext/IIsExtensionData.cs
Expand Up @@ -10,12 +10,6 @@ namespace WixToolset.Iis
/// </summary>
public sealed class IIsExtensionData : BaseExtensionData
{
/// <summary>
/// Gets the default culture.
/// </summary>
/// <value>The default culture.</value>
public override string DefaultCulture => "en-US";

public override bool TryGetSymbolDefinitionByName(string name, out IntermediateSymbolDefinition symbolDefinition)
{
symbolDefinition = IisSymbolDefinitions.ByName(name);
Expand Down
2 changes: 1 addition & 1 deletion src/ext/Iis/wixlib/en-us.wxl
@@ -1,7 +1,7 @@
<!-- 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. -->


<WixLocalization Culture="en-us" xmlns="http://wixtoolset.org/schemas/v4/wxl">
<WixLocalization Culture="en-us" ExtensionDefaultCulture="yes" xmlns="http://wixtoolset.org/schemas/v4/wxl">
<String Id="msierrIISCannotConnect" Overridable="yes" Value="Cannot connect to Internet Information Server. ([2] [3] [4] [5])" />
<String Id="msierrIISFailedReadWebSite" Overridable="yes" Value="Failed while processing WebSites. ([2] [3] [4] [5])" />
<String Id="msierrIISFailedReadWebDirs" Overridable="yes" Value="Failed while processing WebDirs. ([2] [3] [4] [5])" />
Expand Down
6 changes: 0 additions & 6 deletions src/ext/Msmq/wixext/MsmqExtensionData.cs
Expand Up @@ -10,12 +10,6 @@ namespace WixToolset.Msmq
/// </summary>
public sealed class MsmqExtensionData : BaseExtensionData
{
/// <summary>
/// Gets the default culture.
/// </summary>
/// <value>The default culture.</value>
public override string DefaultCulture => "en-US";

public override bool TryGetSymbolDefinitionByName(string name, out IntermediateSymbolDefinition symbolDefinition)
{
symbolDefinition = MsmqSymbolDefinitions.ByName(name);
Expand Down
2 changes: 1 addition & 1 deletion src/ext/Msmq/wixlib/en-us.wxl
@@ -1,7 +1,7 @@
<!-- 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. -->


<WixLocalization Culture="en-us" xmlns="http://wixtoolset.org/schemas/v4/wxl">
<WixLocalization Culture="en-us" ExtensionDefaultCulture="yes" xmlns="http://wixtoolset.org/schemas/v4/wxl">
<String Id="MessageQueuingExecuteInstall" Overridable="yes" Value="Configuring message queues" />
<String Id="MessageQueuingExecuteInstallTemplate" Overridable="yes" Value="Queue: [1]" />
<String Id="MessageQueuingExecuteUninstall" Overridable="yes" Value="Configuring message queues" />
Expand Down
2 changes: 0 additions & 2 deletions src/ext/NetFx/wixext/NetFxExtensionData.cs
Expand Up @@ -10,8 +10,6 @@ namespace WixToolset.Netfx
/// </summary>
public sealed class NetfxExtensionData : BaseExtensionData
{
public override string DefaultCulture => "en-US";

public override bool TryGetSymbolDefinitionByName(string name, out IntermediateSymbolDefinition symbolDefinition)
{
symbolDefinition = NetfxSymbolDefinitions.ByName(name);
Expand Down
6 changes: 0 additions & 6 deletions src/ext/PowerShell/wixext/PSExtensionData.cs
Expand Up @@ -10,12 +10,6 @@ namespace WixToolset.PowerShell
/// </summary>
public sealed class PSExtensionData : BaseExtensionData
{
/// <summary>
/// Gets the default culture.
/// </summary>
/// <value>The default culture.</value>
public override string DefaultCulture => "en-US";

public override Intermediate GetLibrary(ISymbolDefinitionCreator symbolDefinitions)
{
return Intermediate.Load(typeof(PSExtensionData).Assembly, "WixToolset.PowerShell.powershell.wixlib", symbolDefinitions);
Expand Down
6 changes: 0 additions & 6 deletions src/ext/Sql/wixext/SqlExtensionData.cs
Expand Up @@ -10,12 +10,6 @@ namespace WixToolset.Sql
/// </summary>
public sealed class SqlExtensionData : BaseExtensionData
{
/// <summary>
/// Gets the default culture.
/// </summary>
/// <value>The default culture.</value>
public override string DefaultCulture => "en-US";

public override bool TryGetSymbolDefinitionByName(string name, out IntermediateSymbolDefinition symbolDefinition)
{
symbolDefinition = SqlSymbolDefinitions.ByName(name);
Expand Down
2 changes: 1 addition & 1 deletion src/ext/Sql/wixlib/en-us.wxl
@@ -1,7 +1,7 @@
<!-- 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. -->


<WixLocalization Culture="en-us" xmlns="http://wixtoolset.org/schemas/v4/wxl">
<WixLocalization Culture="en-us" ExtensionDefaultCulture="yes" xmlns="http://wixtoolset.org/schemas/v4/wxl">
<String Id="msierrSQLFailedCreateDatabase" Overridable="yes" Value="Error [2]: failed to create SQL database: [3], error detail: [4]." />
<String Id="msierrSQLFailedDropDatabase" Overridable="yes" Value="Error [2]: failed to drop SQL database: [3], error detail: [4]." />
<String Id="msierrSQLFailedConnectDatabase" Overridable="yes" Value="Failed to connect to SQL database. ([2] [3] [4] [5])" />
Expand Down
2 changes: 0 additions & 2 deletions src/ext/UI/wixext/UIExtensionData.cs
Expand Up @@ -7,8 +7,6 @@ namespace WixToolset.UI

public sealed class UIExtensionData : BaseExtensionData
{
public override string DefaultCulture => "en-US";

public override bool TryGetSymbolDefinitionByName(string name, out IntermediateSymbolDefinition symbolDefinition)
{
symbolDefinition = null;
Expand Down
2 changes: 1 addition & 1 deletion src/ext/UI/wixlib/WixUI_en-us.wxl
@@ -1,7 +1,7 @@
<!-- 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. -->


<WixLocalization Culture="en-US" Codepage="1252" xmlns="http://wixtoolset.org/schemas/v4/wxl">
<WixLocalization Culture="en-US" ExtensionDefaultCulture="yes" Codepage="1252" xmlns="http://wixtoolset.org/schemas/v4/wxl">
<!-- _locID@Culture="en-US" _locComment="American English" -->
<!-- _locID@Codepage="1252" _locComment="Windows-1252" -->

Expand Down
2 changes: 0 additions & 2 deletions src/ext/Util/wixext/UtilExtensionData.cs
Expand Up @@ -7,8 +7,6 @@ namespace WixToolset.Util

public sealed class UtilExtensionData : BaseExtensionData
{
public override string DefaultCulture => "en-US";

public override bool TryGetSymbolDefinitionByName(string name, out IntermediateSymbolDefinition symbolDefinition)
{
symbolDefinition = UtilSymbolDefinitions.ByName(name);
Expand Down

0 comments on commit 7be5d94

Please sign in to comment.