From 13f26900846d05d45eaa04f89aeaf2884ec54db5 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Fri, 14 Jun 2024 21:27:50 +0100 Subject: [PATCH] Localize server location notifications --- Bloxstrap/Extensions/ServerTypeEx.cs | 13 +++++++++++++ Bloxstrap/Integrations/ActivityWatcher.cs | 8 ++++---- Bloxstrap/Resources/Strings.Designer.cs | 19 +++++++++++++++++++ Bloxstrap/Resources/Strings.resx | 8 ++++++++ Bloxstrap/UI/NotifyIconWrapper.cs | 10 ++++------ 5 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 Bloxstrap/Extensions/ServerTypeEx.cs diff --git a/Bloxstrap/Extensions/ServerTypeEx.cs b/Bloxstrap/Extensions/ServerTypeEx.cs new file mode 100644 index 0000000..88956d0 --- /dev/null +++ b/Bloxstrap/Extensions/ServerTypeEx.cs @@ -0,0 +1,13 @@ +namespace Bloxstrap.Extensions +{ + static class ServerTypeEx + { + public static string ToTranslatedString(this ServerType value) => value switch + { + ServerType.Public => Resources.Strings.Enums_ServerType_Public, + ServerType.Private => Resources.Strings.Enums_ServerType_Private, + ServerType.Reserved => Resources.Strings.Enums_ServerType_Reserved, + _ => "?" + }; + } +} diff --git a/Bloxstrap/Integrations/ActivityWatcher.cs b/Bloxstrap/Integrations/ActivityWatcher.cs index 431ab5b..19e1182 100644 --- a/Bloxstrap/Integrations/ActivityWatcher.cs +++ b/Bloxstrap/Integrations/ActivityWatcher.cs @@ -294,17 +294,17 @@ var ipInfo = await Http.GetJson($"https://ipinfo.io/{ActivityMachineAddress}/json"); if (ipInfo is null) - return $"N/A ({Resources.Strings.ActivityTracker_LookupFailed})"; + return $"? ({Resources.Strings.ActivityTracker_LookupFailed})"; if (string.IsNullOrEmpty(ipInfo.Country)) - location = "N/A"; + location = "?"; else if (ipInfo.City == ipInfo.Region) location = $"{ipInfo.Region}, {ipInfo.Country}"; else location = $"{ipInfo.City}, {ipInfo.Region}, {ipInfo.Country}"; if (!ActivityInGame) - return $"N/A ({Resources.Strings.ActivityTracker_LeftGame})"; + return $"? ({Resources.Strings.ActivityTracker_LeftGame})"; GeolocationCache[ActivityMachineAddress] = location; @@ -315,7 +315,7 @@ App.Logger.WriteLine(LOG_IDENT, $"Failed to get server location for {ActivityMachineAddress}"); App.Logger.WriteException(LOG_IDENT, ex); - return $"N/A ({Resources.Strings.ActivityTracker_LookupFailed})"; + return $"? ({Resources.Strings.ActivityTracker_LookupFailed})"; } } diff --git a/Bloxstrap/Resources/Strings.Designer.cs b/Bloxstrap/Resources/Strings.Designer.cs index 36742f1..5ba6d2d 100644 --- a/Bloxstrap/Resources/Strings.Designer.cs +++ b/Bloxstrap/Resources/Strings.Designer.cs @@ -548,6 +548,25 @@ namespace Bloxstrap.Resources { } } + /// + /// Looks up a localized string similar to Located at {0} + ///Click for more information. + /// + public static string ContextMenu_ServerInformation_Notification_Text { + get { + return ResourceManager.GetString("ContextMenu.ServerInformation.Notification.Text", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Connected to {0} server. + /// + public static string ContextMenu_ServerInformation_Notification_Title { + get { + return ResourceManager.GetString("ContextMenu.ServerInformation.Notification.Title", resourceCulture); + } + } + /// /// Looks up a localized string similar to Server information. /// diff --git a/Bloxstrap/Resources/Strings.resx b/Bloxstrap/Resources/Strings.resx index 5e777c4..c002509 100644 --- a/Bloxstrap/Resources/Strings.resx +++ b/Bloxstrap/Resources/Strings.resx @@ -283,6 +283,14 @@ Your ReShade configuration files will still be saved, and you can locate them by Location + + Located at {0} +Click for more information + + + Connected to {0} server + Enums.ServerType fills in {0} and is dynamically converted to lowercase when inserted here + Server information diff --git a/Bloxstrap/UI/NotifyIconWrapper.cs b/Bloxstrap/UI/NotifyIconWrapper.cs index 8ed8fea..315acfb 100644 --- a/Bloxstrap/UI/NotifyIconWrapper.cs +++ b/Bloxstrap/UI/NotifyIconWrapper.cs @@ -1,6 +1,4 @@ -using System.Windows; - -using Bloxstrap.Integrations; +using Bloxstrap.Integrations; using Bloxstrap.UI.Elements.ContextMenu; namespace Bloxstrap.UI @@ -91,9 +89,9 @@ namespace Bloxstrap.UI string serverLocation = await _activityWatcher!.GetServerLocation(); ShowAlert( - $"Connected to {_activityWatcher.ActivityServerType.ToString().ToLower()} server", - $"Located at {serverLocation}\nClick for more information", - 10, + String.Format(Resources.Strings.ContextMenu_ServerInformation_Notification_Title, _activityWatcher.ActivityServerType.ToTranslatedString().ToLower()), + String.Format(Resources.Strings.ContextMenu_ServerInformation_Notification_Text, serverLocation), + 10, (_, _) => _menuContainer?.ShowServerInformationWindow() ); }