mirror of
https://github.com/2dust/v2rayN.git
synced 2025-08-30 14:56:19 +00:00
Merge branch 'master' into master_fix
This commit is contained in:
commit
4038497443
2 changed files with 38 additions and 2 deletions
|
@ -1,4 +1,4 @@
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
|
@ -6,14 +6,20 @@ namespace AmazTool
|
||||||
{
|
{
|
||||||
public class LocalizationHelper
|
public class LocalizationHelper
|
||||||
{
|
{
|
||||||
|
|
||||||
private static Dictionary<string, string> languageResources = [];
|
private static Dictionary<string, string> languageResources = [];
|
||||||
|
|
||||||
|
|
||||||
static LocalizationHelper()
|
static LocalizationHelper()
|
||||||
{
|
{
|
||||||
// 加载语言资源
|
// 加载语言资源
|
||||||
LoadLanguageResources();
|
LoadLanguageResources();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加载外部 JSON 文件中的语言资源
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
private static void LoadLanguageResources()
|
private static void LoadLanguageResources()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -24,6 +30,7 @@ namespace AmazTool
|
||||||
currentLanguage = "en-US";
|
currentLanguage = "en-US";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string resourceName = $"AmazTool.{currentLanguage}.json";
|
string resourceName = $"AmazTool.{currentLanguage}.json";
|
||||||
var assembly = Assembly.GetExecutingAssembly();
|
var assembly = Assembly.GetExecutingAssembly();
|
||||||
|
|
||||||
|
@ -57,6 +64,35 @@ namespace AmazTool
|
||||||
public static string GetLocalizedValue(string key)
|
public static string GetLocalizedValue(string key)
|
||||||
{
|
{
|
||||||
if (languageResources.TryGetValue(key, out var translation))
|
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<Dictionary<string, string>>(json) ?? new Dictionary<string, string>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Failed to load language resources: {ex.Message}");
|
||||||
|
languageResources = []; // 初始化为空字典
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取系统当前语言的本地化字符串
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">要翻译的关键字</param>
|
||||||
|
/// <returns>对应语言的本地化字符串,如果没有找到则返回关键字</returns>
|
||||||
|
public static string GetLocalizedValue(string key)
|
||||||
|
{
|
||||||
|
if (languageResources != null && languageResources.TryGetValue(key, out var translation))
|
||||||
|
|
||||||
{
|
{
|
||||||
return translation;
|
return translation;
|
||||||
}
|
}
|
||||||
|
|
|
@ -729,7 +729,7 @@ namespace ServiceLib.ViewModels
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var result = await CoreConfigHandler.GenerateClientConfig(item, null);
|
var result = await CoreConfigHandler.GenerateClientConfig(item, fileName);
|
||||||
if (result.Success != true)
|
if (result.Success != true)
|
||||||
{
|
{
|
||||||
NoticeHandler.Instance.Enqueue(result.Msg);
|
NoticeHandler.Instance.Enqueue(result.Msg);
|
||||||
|
|
Loading…
Reference in a new issue