In our project, there are some cases we want to use StringDatabase.GetLocalizedStringAsync() rather than LocalizedString. Also we created some ISource classes like below, and assign them into ProjectSettings/Localization.
public class LocalizationAccountDataSource : ISource
{
public bool TryEvaluateSelector(ISelectorInfo selectorInfo)
{
if (selectorInfo.CurrentValue == null)
{
if (selectorInfo.SelectorText == "AccountData")
{
selectorInfo.Result = UserData.AccountData;
return true;
}
return false;
}
if (selectorInfo.CurrentValue is UserAccount userAccountData)
{
if (selectorInfo.SelectorText == "NickName")
{
if (string.IsNullOrEmpty(userAccountData.NickName))
{
selectorInfo.Result = ConstantStrings.DefaultName;
}
else
{
selectorInfo.Result = userAccountData.NickName;
}
return true;
}
return false;
}
return false;
}
}
When we called GetLocalizedStringAsync() from LocalizedString or StringTableEntry type, {AccountData} from smart string work well. But when we called GetLocalizedStringAsync() from StringDatabase, selectors marked with SmartString doesn’t work.
private async UniTask StartAsync()
{
await LocalizationSettings.InitializationOperation;
// raw value : "Hello {AccountData.NickName}!"
var localizedText = await new LocalizedString(tableRef, tableEntryRef).GetLocalizedStringAsync();
Debug.Log(localizedText); // "Hello Commander64!"
var getTableEntryResult =
await LocalizationSettings.StringDatabase.GetTableEntryAsync(tableRef, tableEntryKey);
Debug.Log(getTableEntryResult.Entry.GetLocalizedString()); // "Hello Commander64!"
localizedText = await LocalizationSettings.StringDatabase.GetLocalizedStringAsync(tableRef, tableEntryRef);
Debug.Log(localizedText); // "Hello {AccountData.NickName}!"
}
Is this the intended behavior? or there is something I missed?