using I2.Loc; using UnityEngine; namespace SLSFramework.General { public static class StringExtension { /// /// 本地化字符串,不使用参数替换 /// /// 原始字符串 /// public static string Localize(this string original) { if (LocalizationManager.TryGetTranslation(original, out string translated)) { return translated; } return original; } /// /// 本地化字符串,使用指定的根GameObject进行i2Loc参数替换 /// /// 原始字符串 /// 用于参数替换,含有LocalizationParamsManager的根GameObject,设为null则表明使用全局参数 /// public static string Localize(this string original, GameObject rootGameObject) { if (rootGameObject != null && rootGameObject.GetComponent() == null) { throw new System.ArgumentException("The provided rootGameObject does not contain a LocalizationParamsManager component."); } if (LocalizationManager.TryGetTranslation(original, out string translated, true, 0, true, true, rootGameObject)) { return translated; } return original; } } }