From e40683557f621df00cf99330fa480f0cbe0a7a72 Mon Sep 17 00:00:00 2001 From: ayuan9957 <107920784+ayuan9957@users.noreply.github.com> Date: Fri, 17 Jul 2026 11:07:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20InputField=E5=8D=A0=E4=BD=8D=E7=AC=A6?= =?UTF-8?q?=E5=AE=9E=E6=97=B6=E7=BF=BB=E8=AF=91=20+=20=E9=80=9F=E9=99=90/?= =?UTF-8?q?=E6=95=B0=E9=87=8F/=E5=8F=B0=E6=A0=87=E7=AD=BE=E7=BF=BB?= =?UTF-8?q?=E8=AF=91=20-=20RefreshAll=E6=96=B0=E5=A2=9EInputField=E9=81=8D?= =?UTF-8?q?=E5=8E=86=EF=BC=8C=E7=94=A8=E6=88=B7=E8=BE=93=E5=85=A5=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E4=B8=8D=E5=8F=97=E5=BD=B1=E5=93=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Localization/LocalizationManager.cs | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/Assets/Scripts/Localization/LocalizationManager.cs b/Assets/Scripts/Localization/LocalizationManager.cs index 93a649b..9b2ef04 100644 --- a/Assets/Scripts/Localization/LocalizationManager.cs +++ b/Assets/Scripts/Localization/LocalizationManager.cs @@ -30,6 +30,13 @@ public class LocalizationManager : MonoBehaviour public bool fontApplied; } + private class InputFieldState + { + public string source; + public string localized; + public bool fontApplied; + } + // Pre-built lookup dictionaries for O(1) translation private Dictionary reverseTable; private Dictionary normalizedTable; @@ -41,6 +48,7 @@ public class LocalizationManager : MonoBehaviour private static LocalizationManager instance; private readonly Dictionary textStates = new Dictionary(); private readonly Dictionary dropdownStates = new Dictionary(); + private readonly Dictionary inputFieldStates = new Dictionary(); private readonly Dictionary table = new Dictionary { @@ -507,6 +515,15 @@ public class LocalizationManager : MonoBehaviour { "触发物体", new[] { "触发物体", "Trigger Object", "Activer l'objet", "Активировать объект" } }, { "抓取物体", new[] { "抓取物体", "Grab Object", "Saisir l'objet", "Захватить объект" } }, { "传送", new[] { "传送", "Teleport", "Téléportation", "Телепорт" } }, + + // Equipment item labels (Image_equip1.prefab, Canvas.prefab) + { "速限:", new[] { "速限:", "Speed Limit:", "Limite de vitesse :", "Ограничение скорости:" } }, + { "数量:", new[] { "数量:", "Quantity:", "Quantité :", "Количество:" } }, + { "台", new[] { "台", "units", "unités", "ед." } }, + { "速限: km/h", new[] { "速限: km/h", "Speed Limit: km/h", "Limite de vitesse : km/h", "Ограничение скорости: км/ч" } }, + { "速限: km/h", new[] { "速限: km/h", "Speed Limit: km/h", "Limite de vitesse : km/h", "Ограничение скорости: км/ч" } }, + { "数量: 台", new[] { "数量: 台", "Quantity: units", "Quantité : unités", "Количество: ед." } }, + { "数量: 台", new[] { "数量: 台", "Quantity: units", "Quantité : unités", "Количество: ед." } }, }; [SerializeField] private int language; @@ -744,6 +761,9 @@ public class LocalizationManager : MonoBehaviour Dropdown[] dropdowns = FindObjectsOfType(); for (int i = 0; i < dropdowns.Length; i++) Localize(dropdowns[i]); + + InputField[] inputs = FindObjectsOfType(); + for (int i = 0; i < inputs.Length; i++) Localize(inputs[i]); } private string Translate(string source) @@ -1080,4 +1100,41 @@ public class LocalizationManager : MonoBehaviour dropdown.RefreshShownValue(); } + + /// + /// Localize the placeholder text of an InputField. User-entered text is never touched. + /// + private void Localize(InputField input) + { + if (input == null || !input.gameObject.scene.IsValid()) return; + if (input.placeholder == null) return; + + Text placeholder = input.placeholder as Text; + if (placeholder == null) return; + + int id = input.GetInstanceID(); + InputFieldState state; + if (!inputFieldStates.TryGetValue(id, out state)) + { + state = new InputFieldState { source = placeholder.text, localized = placeholder.text }; + inputFieldStates.Add(id, state); + } + else if (placeholder.text != state.localized) + { + state.source = GetSourceText(placeholder.text); + } + + // Apply font once + if (font != null && !state.fontApplied) + { + Color savedColor = placeholder.color; + placeholder.font = font; + placeholder.color = savedColor; + placeholder.verticalOverflow = VerticalWrapMode.Overflow; + state.fontApplied = true; + } + + state.localized = Translate(state.source); + placeholder.text = state.localized; + } }