2026-04-08 04:48:35 -04:00
|
|
|
|
using Continentis.MainGame;
|
|
|
|
|
|
using Continentis.MainGame.Card;
|
2025-10-23 00:49:44 -04:00
|
|
|
|
using I2.Loc;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
namespace SLSFramework.General
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class StringExtension
|
|
|
|
|
|
{
|
2025-12-12 01:37:30 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 本地化字符串,不使用参数替换
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="original">原始字符串</param>
|
|
|
|
|
|
/// <returns></returns>
|
2025-10-23 00:49:44 -04:00
|
|
|
|
public static string Localize(this string original)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (LocalizationManager.TryGetTranslation(original, out string translated))
|
|
|
|
|
|
{
|
|
|
|
|
|
return translated;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return original;
|
|
|
|
|
|
}
|
2025-12-12 01:37:30 -05:00
|
|
|
|
|
2026-04-08 04:48:35 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 本地化字符串,并使用卡牌上下文解析 $Attribute / $Keyword 等文本内函数
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="original">本地化 Key</param>
|
|
|
|
|
|
/// <param name="card">提供属性上下文的卡牌实例</param>
|
|
|
|
|
|
/// <returns>翻译并解析后的最终文本</returns>
|
|
|
|
|
|
public static string Localize(this string original, CardInstance card)
|
|
|
|
|
|
{
|
|
|
|
|
|
string translated = original.Localize();
|
|
|
|
|
|
return CardTextInterpreter.InterpretText(card, translated);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-12 01:37:30 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 本地化字符串,使用指定的根GameObject进行i2Loc参数替换
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="original">原始字符串</param>
|
|
|
|
|
|
/// <param name="rootGameObject">用于参数替换,含有LocalizationParamsManager的根GameObject,设为null则表明使用全局参数</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static string Localize(this string original, GameObject rootGameObject)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (rootGameObject != null && rootGameObject.GetComponent<LocalizationParamsManager>() == 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;
|
|
|
|
|
|
}
|
2025-10-23 00:49:44 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|