mirror of
https://github.com/2dust/v2rayN.git
synced 2025-08-30 14:56:19 +00:00
Update LocalizationHelper.cs
This commit is contained in:
parent
4038497443
commit
df71764d1e
1 changed files with 1 additions and 37 deletions
|
@ -6,20 +6,14 @@ namespace AmazTool
|
|||
{
|
||||
public class LocalizationHelper
|
||||
{
|
||||
|
||||
private static Dictionary<string, string> languageResources = [];
|
||||
|
||||
|
||||
static LocalizationHelper()
|
||||
{
|
||||
// 加载语言资源
|
||||
LoadLanguageResources();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载外部 JSON 文件中的语言资源
|
||||
/// </summary>
|
||||
|
||||
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<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;
|
||||
}
|
||||
|
@ -100,4 +64,4 @@ namespace AmazTool
|
|||
return key;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue