From 10513e0f3bce0a99b7bb6d05c3a36a78ee686d8f Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Mon, 18 Nov 2024 09:56:13 +0800 Subject: [PATCH 1/3] Fixed the problem that the statistics column would not be hidden --- v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs | 2 +- v2rayN/v2rayN/Views/ProfilesView.xaml.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs index a2bfa298..4508daa5 100644 --- a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs @@ -356,7 +356,7 @@ namespace v2rayN.Desktop.Views item2.Width = new DataGridLength(item.Width, DataGridLengthUnitType.Pixel); item2.DisplayIndex = displayIndex++; } - if (item.Name.StartsWith("to")) + if (item.Name.ToLower().StartsWith("to")) { if (!_config.GuiItem.EnableStatistics) { diff --git a/v2rayN/v2rayN/Views/ProfilesView.xaml.cs b/v2rayN/v2rayN/Views/ProfilesView.xaml.cs index 23459fc1..e39c7dff 100644 --- a/v2rayN/v2rayN/Views/ProfilesView.xaml.cs +++ b/v2rayN/v2rayN/Views/ProfilesView.xaml.cs @@ -338,7 +338,7 @@ namespace v2rayN.Views item2.Width = item.Width; item2.DisplayIndex = displayIndex++; } - if (item.Name.StartsWith("to")) + if (item.Name.ToLower().StartsWith("to")) { if (!_config.GuiItem.EnableStatistics) { From 1866a59d12a4f663dd7d1ca0e55223d9496596b8 Mon Sep 17 00:00:00 2001 From: Slnanx Date: Mon, 18 Nov 2024 09:57:38 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E5=86=85=E5=B5=8C=E8=B5=84=E6=BA=90=E6=96=87=E4=BB=B6=20(#6101?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix * fix * 移除自述 * 改用单例模式,避免多次初始化。 * 小修正 * 修正 * 更正自述 * 应该完成了 * 内嵌资源 * Update LocalizationHelper.cs --- v2rayN/AmazTool/LocalizationHelper.cs | 46 +++++++++++++++------------ 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/v2rayN/AmazTool/LocalizationHelper.cs b/v2rayN/AmazTool/LocalizationHelper.cs index 3804564c..839be22e 100644 --- a/v2rayN/AmazTool/LocalizationHelper.cs +++ b/v2rayN/AmazTool/LocalizationHelper.cs @@ -1,11 +1,12 @@ -using System.Globalization; +using System.Globalization; +using System.Reflection; using System.Text.Json; namespace AmazTool { public class LocalizationHelper { - private static Dictionary languageResources = new(); + private static Dictionary languageResources = []; static LocalizationHelper() { @@ -13,9 +14,6 @@ namespace AmazTool LoadLanguageResources(); } - /// - /// 加载外部 JSON 文件中的语言资源 - /// private static void LoadLanguageResources() { try @@ -26,33 +24,39 @@ namespace AmazTool currentLanguage = "en-US"; } - string jsonFilePath = $"{currentLanguage}.json"; - if (!File.Exists(jsonFilePath)) - { - jsonFilePath = "en-US.json"; - } + string resourceName = $"AmazTool.{currentLanguage}.json"; + var assembly = Assembly.GetExecutingAssembly(); - var json = File.ReadAllText(jsonFilePath); - if (!string.IsNullOrEmpty(json)) + using Stream? stream = assembly.GetManifestResourceStream(resourceName); + if (stream != null) { - languageResources = JsonSerializer.Deserialize>(json) ?? new Dictionary(); + using StreamReader reader = new(stream); + + var json = reader.ReadToEnd(); + + if (!string.IsNullOrEmpty(json)) + { + languageResources = JsonSerializer.Deserialize>(json) ?? new Dictionary(); + } } } + catch (IOException ex) + { + Console.WriteLine($"Failed to read language resource file: {ex.Message}"); + } + catch (JsonException ex) + { + Console.WriteLine($"Failed to parse JSON data: {ex.Message}"); + } catch (Exception ex) { - Console.WriteLine($"Failed to load language resources: {ex.Message}"); - languageResources = []; // 初始化为空字典 + Console.WriteLine($"Unexpected error occurred: {ex.Message}"); } } - /// - /// 获取系统当前语言的本地化字符串 - /// - /// 要翻译的关键字 - /// 对应语言的本地化字符串,如果没有找到则返回关键字 public static string GetLocalizedValue(string key) { - if (languageResources != null && languageResources.TryGetValue(key, out var translation)) + if (languageResources.TryGetValue(key, out var translation)) { return translation; } From 499a16feae524791e7d10909e432d292ab1d78a4 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Mon, 18 Nov 2024 10:13:49 +0800 Subject: [PATCH 3/3] Fix LocalizationHelper for AmazTool --- v2rayN/AmazTool/AmazTool.csproj | 5 +++++ v2rayN/AmazTool/{ => Assets}/en-US.json | 0 v2rayN/AmazTool/{ => Assets}/zh-CN.json | 0 v2rayN/AmazTool/LocalizationHelper.cs | 30 +++++++++---------------- 4 files changed, 16 insertions(+), 19 deletions(-) rename v2rayN/AmazTool/{ => Assets}/en-US.json (100%) rename v2rayN/AmazTool/{ => Assets}/zh-CN.json (100%) diff --git a/v2rayN/AmazTool/AmazTool.csproj b/v2rayN/AmazTool/AmazTool.csproj index 37193d62..05874af3 100644 --- a/v2rayN/AmazTool/AmazTool.csproj +++ b/v2rayN/AmazTool/AmazTool.csproj @@ -8,5 +8,10 @@ Copyright © 2017-2024 (GPLv3) 1.3.0 + + + + + \ No newline at end of file diff --git a/v2rayN/AmazTool/en-US.json b/v2rayN/AmazTool/Assets/en-US.json similarity index 100% rename from v2rayN/AmazTool/en-US.json rename to v2rayN/AmazTool/Assets/en-US.json diff --git a/v2rayN/AmazTool/zh-CN.json b/v2rayN/AmazTool/Assets/zh-CN.json similarity index 100% rename from v2rayN/AmazTool/zh-CN.json rename to v2rayN/AmazTool/Assets/zh-CN.json diff --git a/v2rayN/AmazTool/LocalizationHelper.cs b/v2rayN/AmazTool/LocalizationHelper.cs index 839be22e..4af352c6 100644 --- a/v2rayN/AmazTool/LocalizationHelper.cs +++ b/v2rayN/AmazTool/LocalizationHelper.cs @@ -6,7 +6,7 @@ namespace AmazTool { public class LocalizationHelper { - private static Dictionary languageResources = []; + private static Dictionary _languageResources = []; static LocalizationHelper() { @@ -18,26 +18,23 @@ namespace AmazTool { try { - string currentLanguage = CultureInfo.CurrentCulture.Name; + var currentLanguage = CultureInfo.CurrentCulture.Name; if (currentLanguage != "zh-CN" && currentLanguage != "en-US") { currentLanguage = "en-US"; } - string resourceName = $"AmazTool.{currentLanguage}.json"; + var resourceName = $"AmazTool.Assets.{currentLanguage}.json"; var assembly = Assembly.GetExecutingAssembly(); - using Stream? stream = assembly.GetManifestResourceStream(resourceName); - if (stream != null) + using var stream = assembly.GetManifestResourceStream(resourceName); + if (stream == null) return; + + using StreamReader reader = new(stream); + var json = reader.ReadToEnd(); + if (!string.IsNullOrEmpty(json)) { - using StreamReader reader = new(stream); - - var json = reader.ReadToEnd(); - - if (!string.IsNullOrEmpty(json)) - { - languageResources = JsonSerializer.Deserialize>(json) ?? new Dictionary(); - } + _languageResources = JsonSerializer.Deserialize>(json) ?? new Dictionary(); } } catch (IOException ex) @@ -56,12 +53,7 @@ namespace AmazTool public static string GetLocalizedValue(string key) { - if (languageResources.TryGetValue(key, out var translation)) - { - return translation; - } - - return key; + return _languageResources.TryGetValue(key, out var translation) ? translation : key; } } }