Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Globalization;
using System.Windows.Data;
using NETworkManager.Localization;
using NETworkManager.Models.Firewall;

namespace NETworkManager.Converters;

/// <summary>
/// Convert <see cref="FirewallInterfaceType" /> to translated <see cref="string" /> or vice versa.
/// </summary>
public sealed class FirewallInterfaceTypeToStringConverter : IValueConverter
{
/// <summary>
/// Convert <see cref="FirewallInterfaceType" /> to translated <see cref="string" />.
/// </summary>
/// <param name="value">Object from type <see cref="FirewallInterfaceType" />.</param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns>Translated <see cref="FirewallInterfaceType" />.</returns>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value is not FirewallInterfaceType interfaceType
? "-/-"
: ResourceTranslator.Translate(ResourceIdentifier.FirewallInterfaceType, interfaceType);
}

/// <summary>
/// !!! Method not implemented !!!
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns></returns>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Data;
using NETworkManager.Localization.Resources;

namespace NETworkManager.Converters;

/// <summary>
/// Convert a <see cref="bool" /> array (Domain, Private, Public) representing firewall network
/// profiles to a localized <see cref="string" />, or vice versa.
/// </summary>
public sealed class FirewallNetworkProfilesToStringConverter : IValueConverter
{
/// <summary>
/// Convert a <see cref="bool" /> array (Domain, Private, Public) to a localized <see cref="string" />.
/// Returns <c>null</c> when all three profiles are active so that a <c>TargetNullValue</c> binding
/// can supply the translated "Any" label.
/// </summary>
/// <param name="value">A <see cref="bool" /> array with exactly three elements.</param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns>Localized, comma-separated profile list (e.g. "Domain, Private, Public").</returns>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is not bool[] { Length: 3 } profiles)
return "-/-";

var names = new List<string>(3);
if (profiles[0]) names.Add(Strings.Domain);
if (profiles[1]) names.Add(Strings.Private);
if (profiles[2]) names.Add(Strings.Public);

return names.Count == 0 ? "-" : string.Join(", ", names);
}

/// <summary>
/// !!! Method not implemented !!!
/// </summary>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Globalization;
using System.Windows.Data;
using NETworkManager.Localization;
using NETworkManager.Models.Firewall;

namespace NETworkManager.Converters;

/// <summary>
/// Convert <see cref="FirewallProtocol" /> to translated <see cref="string" /> or vice versa.
/// </summary>
public sealed class FirewallProtocolToStringConverter : IValueConverter
{
/// <summary>
/// Convert <see cref="FirewallProtocol" /> to translated <see cref="string" />.
/// </summary>
/// <param name="value">Object from type <see cref="FirewallProtocol" />.</param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns>Translated <see cref="FirewallProtocol" />.</returns>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value is not FirewallProtocol protocol
? "-/-"
: ResourceTranslator.Translate(ResourceIdentifier.FirewallProtocol, protocol);
}

/// <summary>
/// !!! Method not implemented !!!
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns></returns>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Globalization;
using System.Windows.Data;
using NETworkManager.Localization.Resources;
using NETworkManager.Models.Network;

namespace NETworkManager.Converters;

/// <summary>
/// Convert <see cref="NetworkProfile" /> to a localized <see cref="string" /> or vice versa.
/// </summary>
public sealed class NetworkProfileToStringConverter : IValueConverter
{
/// <summary>
/// Convert <see cref="NetworkProfile" /> to a localized <see cref="string" />.
/// </summary>
/// <param name="value">Object from type <see cref="NetworkProfile" />.</param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns>Localized <see cref="string" /> representing the network profile.</returns>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value is not NetworkProfile profile
? "-/-"
: profile switch
{
NetworkProfile.Domain => Strings.Domain,
NetworkProfile.Private => Strings.Private,
NetworkProfile.Public => Strings.Public,
_ => "-/-"
};
}

/// <summary>
/// !!! Method not implemented !!!
/// </summary>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
4 changes: 3 additions & 1 deletion Source/NETworkManager.Localization/ResourceIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ public enum ResourceIdentifier
TcpState,
Theme,
TimeUnit,
WiFiConnectionStatus
WiFiConnectionStatus,
FirewallProtocol,
FirewallInterfaceType
}
29 changes: 28 additions & 1 deletion Source/NETworkManager.Localization/Resources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions Source/NETworkManager.Localization/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2151,6 +2151,12 @@ is disabled!</value>
<data name="Program" xml:space="preserve">
<value>Program</value>
</data>
<data name="Private" xml:space="preserve">
<value>Private</value>
</data>
<data name="Public" xml:space="preserve">
<value>Public</value>
</data>
<data name="DeleteCustomCommandMessage" xml:space="preserve">
<value>The selected custom command will be deleted permanently.</value>
</data>
Expand Down Expand Up @@ -4037,6 +4043,9 @@ You can copy your profile files from “{0}” to “{1}” to migrate your exis
<data name="Block" xml:space="preserve">
<value>Block</value>
</data>
<data name="NetworkProfile" xml:space="preserve">
<value>Network profile</value>
</data>
<data name="NetworkProfiles" xml:space="preserve">
<value>Network profiles</value>
</data>
Expand All @@ -4046,4 +4055,61 @@ You can copy your profile files from “{0}” to “{1}” to migrate your exis
<data name="FailedToLoadFirewallRulesMessage" xml:space="preserve">
<value>Failed to load firewall rules. {0}</value>
</data>
<data name="FirewallProtocol_Any" xml:space="preserve">
<value>Any</value>
</data>
<data name="FirewallProtocol_TCP" xml:space="preserve">
<value>TCP</value>
</data>
<data name="FirewallProtocol_UDP" xml:space="preserve">
<value>UDP</value>
</data>
<data name="FirewallProtocol_ICMPv4" xml:space="preserve">
<value>ICMPv4</value>
</data>
<data name="FirewallProtocol_ICMPv6" xml:space="preserve">
<value>ICMPv6</value>
</data>
<data name="FirewallProtocol_HOPOPT" xml:space="preserve">
<value>HOPOPT</value>
</data>
<data name="FirewallProtocol_GRE" xml:space="preserve">
<value>GRE</value>
</data>
<data name="FirewallProtocol_IPv6" xml:space="preserve">
<value>IPv6</value>
</data>
<data name="FirewallProtocol_IPv6_Route" xml:space="preserve">
<value>IPv6-Route</value>
</data>
<data name="FirewallProtocol_IPv6_Frag" xml:space="preserve">
<value>IPv6-Frag</value>
</data>
<data name="FirewallProtocol_IPv6_NoNxt" xml:space="preserve">
<value>IPv6-NoNxt</value>
</data>
<data name="FirewallProtocol_IPv6_Opts" xml:space="preserve">
<value>IPv6-Opts</value>
</data>
<data name="FirewallProtocol_VRRP" xml:space="preserve">
<value>VRRP</value>
</data>
<data name="FirewallProtocol_PGM" xml:space="preserve">
<value>PGM</value>
</data>
<data name="FirewallProtocol_L2TP" xml:space="preserve">
<value>L2TP</value>
</data>
<data name="FirewallInterfaceType_Any" xml:space="preserve">
<value>Any</value>
</data>
<data name="FirewallInterfaceType_Wired" xml:space="preserve">
<value>Wired</value>
</data>
<data name="FirewallInterfaceType_Wireless" xml:space="preserve">
<value>Wireless</value>
</data>
<data name="FirewallInterfaceType_RemoteAccess" xml:space="preserve">
<value>Remote access</value>
</data>
</root>
Loading
Loading