From 450dacdeb6991e79c8ffe664e01d3a1d9ef53a04 Mon Sep 17 00:00:00 2001
From: uye <99072975+ABA2396@users.noreply.github.com>
Date: Wed, 23 Jul 2025 19:07:42 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B5=8C=E5=A5=97=E7=BF=BB=E8=AF=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/MaaWpfGui/Helper/LocalizationHelper.cs | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/src/MaaWpfGui/Helper/LocalizationHelper.cs b/src/MaaWpfGui/Helper/LocalizationHelper.cs
index 1864638687..b8d8e3f9fa 100644
--- a/src/MaaWpfGui/Helper/LocalizationHelper.cs
+++ b/src/MaaWpfGui/Helper/LocalizationHelper.cs
@@ -160,7 +160,6 @@ namespace MaaWpfGui.Helper
continue;
}
-
dictionary[key] = GetFormattedString(key, culture);
}
}
@@ -217,12 +216,27 @@ namespace MaaWpfGui.Helper
/// The formatted string.
private static string GetFormattedString(string key, string? culture = null)
{
- var raw = GetString(key, culture);
- return Regex.Replace(raw, @"\{key=(\w+)\}", match =>
+ return ResolveNestedKeys(key, GetString(key, culture), culture, new());
+ }
+
+ private static string ResolveNestedKeys(string currentKey, string input, string? culture, Stack visited)
+ {
+ if (visited.Contains(currentKey))
+ {
+ throw new InvalidOperationException($"Circular reference: {string.Join(" -> ", visited.Reverse())} -> {currentKey}");
+ }
+
+ visited.Push(currentKey);
+
+ var result = Regex.Replace(input, @"\{key=(\w+)\}", match =>
{
var innerKey = match.Groups[1].Value;
- return GetString(innerKey, culture);
+ var innerValue = GetString(innerKey, culture);
+ return ResolveNestedKeys(innerKey, innerValue, culture, visited);
});
+
+ visited.Pop();
+ return result;
}
private static readonly string[] _pallasChars = ["💃", "🕺", "🍷", "🍸", "🍺", "🍻", "🍷", "🍸", "🍺", "🍻"];