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] 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;
}
}
}