using Continentis.MainGame;
using Continentis.MainGame.Card;
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;
}
///
/// 本地化字符串,并使用卡牌上下文解析 $Attribute / $Keyword 等文本内函数
///
/// 本地化 Key
/// 提供属性上下文的卡牌实例
/// 翻译并解析后的最终文本
public static string Localize(this string original, CardInstance card)
{
string translated = original.Localize();
return CardTextInterpreter.InterpretText(card, translated);
}
///
/// 本地化字符串,使用指定的根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;
}
}
}