diff --git a/v2rayN/AmazTool/LocalizationHelper.cs b/v2rayN/AmazTool/LocalizationHelper.cs index 102dd957..a2166a10 100644 --- a/v2rayN/AmazTool/LocalizationHelper.cs +++ b/v2rayN/AmazTool/LocalizationHelper.cs @@ -1,4 +1,4 @@ -using System.Globalization; +using System.Globalization; using System.Reflection; using System.Text.Json; @@ -6,14 +6,20 @@ namespace AmazTool { public class LocalizationHelper { + private static Dictionary languageResources = []; + static LocalizationHelper() { // 加载语言资源 LoadLanguageResources(); } + /// + /// 加载外部 JSON 文件中的语言资源 + /// + private static void LoadLanguageResources() { try @@ -24,6 +30,7 @@ namespace AmazTool currentLanguage = "en-US"; } + string resourceName = $"AmazTool.{currentLanguage}.json"; var assembly = Assembly.GetExecutingAssembly(); @@ -57,6 +64,35 @@ 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; } diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs index d3ca25e8..b4a2f982 100644 --- a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs @@ -729,7 +729,7 @@ namespace ServiceLib.ViewModels { return; } - var result = await CoreConfigHandler.GenerateClientConfig(item, null); + var result = await CoreConfigHandler.GenerateClientConfig(item, fileName); if (result.Success != true) { NoticeHandler.Instance.Enqueue(result.Msg);