From 7c0c52ac9fcf64ad9b54e22dc29eb8550b375625 Mon Sep 17 00:00:00 2001 From: ayuan9957 <107920784+ayuan9957@users.noreply.github.com> Date: Thu, 16 Jul 2026 17:10:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BF=BB=E8=AF=91=E6=A8=A1=E7=B3=8A?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=20-=20=E8=A7=84=E8=8C=83=E5=8C=96=E7=A9=BA?= =?UTF-8?q?=E7=99=BD=E5=AD=97=E7=AC=A6=E8=A7=A3=E5=86=B3=E6=8D=A2=E8=A1=8C?= =?UTF-8?q?/=E7=A9=BA=E6=A0=BC=E5=8F=98=E4=BD=93=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - GetSourceText: 精确匹配失败后尝试规范化空白匹配 - Translate: TryGetValue失败后尝试规范化空白匹配 - 所有换行符(\\r\\n/\\n)和空格变体都能匹配到翻译表 --- .../Localization/LocalizationManager.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Assets/Scripts/Localization/LocalizationManager.cs b/Assets/Scripts/Localization/LocalizationManager.cs index 6e41ed1..3fb13bb 100644 --- a/Assets/Scripts/Localization/LocalizationManager.cs +++ b/Assets/Scripts/Localization/LocalizationManager.cs @@ -704,6 +704,16 @@ public class LocalizationManager : MonoBehaviour string[] values; if (table.TryGetValue(source, out values) && values != null && language < values.Length && values[language] != null) return values[language]; + + // Fuzzy: try normalized lookup + string normalized = System.Text.RegularExpressions.Regex.Replace(source, @"\s+", " ").Trim(); + foreach (KeyValuePair pair in table) + { + string nk = System.Text.RegularExpressions.Regex.Replace(pair.Key, @"\s+", " ").Trim(); + if (nk == normalized && pair.Value != null && language < pair.Value.Length && pair.Value[language] != null) + return pair.Value[language]; + } + return source; } @@ -711,6 +721,7 @@ public class LocalizationManager : MonoBehaviour { if (string.IsNullOrEmpty(value) || table.ContainsKey(value)) return value; + // Exact match foreach (KeyValuePair pair in table) { if (pair.Value == null || pair.Value.Length <= 1) continue; @@ -721,6 +732,21 @@ public class LocalizationManager : MonoBehaviour } } + // Fuzzy match: normalize whitespace (newlines, tabs, multiple spaces → single space) + string normalizedValue = System.Text.RegularExpressions.Regex.Replace(value, @"\s+", " ").Trim(); + foreach (KeyValuePair pair in table) + { + if (pair.Value == null || pair.Value.Length <= 1) continue; + string normalizedKey = System.Text.RegularExpressions.Regex.Replace(pair.Key, @"\s+", " ").Trim(); + if (normalizedKey == normalizedValue) return pair.Key; + for (int i = 1; i < pair.Value.Length; i++) + { + if (pair.Value[i] == null) continue; + string normalizedVal = System.Text.RegularExpressions.Regex.Replace(pair.Value[i], @"\s+", " ").Trim(); + if (normalizedVal == normalizedValue) return pair.Key; + } + } + return value; }