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,41 @@
using System;
using System.Globalization;
using System.Windows.Data;
using NETworkManager.Localization;
using NETworkManager.Models.Firewall;

namespace NETworkManager.Converters;

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

/// <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,41 @@
using System;
using System.Globalization;
using System.Windows.Data;
using NETworkManager.Localization;
using NETworkManager.Models.Firewall;

namespace NETworkManager.Converters;

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

/// <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();
}
}
6 changes: 5 additions & 1 deletion Source/NETworkManager.Localization/ResourceIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ public enum ResourceIdentifier
TcpState,
Theme,
TimeUnit,
WiFiConnectionStatus
WiFiConnectionStatus,
FirewallProtocol,
FirewallInterfaceType,
FirewallRuleDirection,
FirewallRuleAction
}
40 changes: 38 additions & 2 deletions Source/NETworkManager.Localization/Resources/Strings.Designer.cs

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

Loading
Loading