From df71764d1e5a2ebf41c4e3c56b006f7ce08a6209 Mon Sep 17 00:00:00 2001 From: Slnanx Date: Sun, 17 Nov 2024 21:15:44 +0800 Subject: [PATCH] Update LocalizationHelper.cs --- v2rayN/AmazTool/LocalizationHelper.cs | 38 +-------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/v2rayN/AmazTool/LocalizationHelper.cs b/v2rayN/AmazTool/LocalizationHelper.cs index a2166a10..839be22e 100644 --- a/v2rayN/AmazTool/LocalizationHelper.cs +++ b/v2rayN/AmazTool/LocalizationHelper.cs @@ -6,20 +6,14 @@ namespace AmazTool { public class LocalizationHelper { - private static Dictionary languageResources = []; - static LocalizationHelper() { // 加载语言资源 LoadLanguageResources(); } - /// - /// 加载外部 JSON 文件中的语言资源 - /// - private static void LoadLanguageResources() { try @@ -30,7 +24,6 @@ namespace AmazTool currentLanguage = "en-US"; } - string resourceName = $"AmazTool.{currentLanguage}.json"; var assembly = Assembly.GetExecutingAssembly(); @@ -64,35 +57,6 @@ namespace AmazTool public static string GetLocalizedValue(string key) { if (languageResources.TryGetValue(key, out var translation)) - - string jsonFilePath = $"{currentLanguage}.json"; - if (!File.Exists(jsonFilePath)) - { - jsonFilePath = "en-US.json"; - } - - var json = File.ReadAllText(jsonFilePath); - if (!string.IsNullOrEmpty(json)) - { - languageResources = JsonSerializer.Deserialize>(json) ?? new Dictionary(); - } - } - catch (Exception ex) - { - Console.WriteLine($"Failed to load language resources: {ex.Message}"); - languageResources = []; // 初始化为空字典 - } - } - - /// - /// 获取系统当前语言的本地化字符串 - /// - /// 要翻译的关键字 - /// 对应语言的本地化字符串,如果没有找到则返回关键字 - public static string GetLocalizedValue(string key) - { - if (languageResources != null && languageResources.TryGetValue(key, out var translation)) - { return translation; } @@ -100,4 +64,4 @@ namespace AmazTool return key; } } -} \ No newline at end of file +}