36 lines
939 B
C#
36 lines
939 B
C#
using UnityEngine;
|
|
using UnityEngine.Localization.Settings;
|
|
|
|
namespace SLSUtilities.General
|
|
{
|
|
public static class StringExtension
|
|
{
|
|
/// <summary>
|
|
/// 根据 Key 从指定 Table 中获取本地化文本。
|
|
/// 若本地化系统尚未初始化或 Key 不存在,则原样返回。
|
|
/// </summary>
|
|
public static string Localize(this string key, string tableName)
|
|
{
|
|
if (string.IsNullOrEmpty(key))
|
|
{
|
|
return key;
|
|
}
|
|
|
|
if (!LocalizationSettings.HasSettings ||
|
|
LocalizationSettings.SelectedLocale == null)
|
|
{
|
|
return key;
|
|
}
|
|
|
|
string result = LocalizationSettings.StringDatabase.GetLocalizedString(tableName, key);
|
|
|
|
if (string.IsNullOrEmpty(result))
|
|
{
|
|
return key;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|