I want to load from script several localization tables by using GetTableAsync
passing the TableReference
of each one, so then I can use LocalizedString.GetLocalizedString().Result
synchronously. I was using TableReference
s with the table collection name set, but I couldn’t get the localized strings synchronously, LocalizedString.GetLocalizedString().Result
always returned null. But I tried using the table GUIDs instead, and it works. Is using the collection name not supported for some reason, could it be a bug, or am I missing something?
I’m using the package version 0.10.0, I think I remember it working in 0.9.0, but I’m not 100% sure because I’ve made several code changes since then.
This is some minimal test script where the issue happens:
using System.Collections;
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;
using UnityEngine.Localization.Tables;
using UnityEngine.ResourceManagement.AsyncOperations;
public class TestManualTableLoad : MonoBehaviour
{
[SerializeField] TableReference tableReference = default;
[SerializeField] LocalizedString stringFromTable = default;
IEnumerator Start()
{
// Wait for initialization:
if (!LocalizationSettings.InitializationOperation.IsDone)
yield return LocalizationSettings.InitializationOperation;
if (LocalizationSettings.InitializationOperation.Status == AsyncOperationStatus.Failed)
{
Debug.LogError("Initialization failed");
yield break;
}
// Try to load the table:
var manualLoadOper = LocalizationSettings.StringDatabase.GetTableAsync(tableReference);
if (!manualLoadOper.IsDone)
yield return manualLoadOper;
Debug.Log($"Load status: \"{manualLoadOper.Status}\", result: \"{manualLoadOper.Result}\"");
string text = stringFromTable.GetLocalizedString().Result;
Debug.Log($"Localized string: \"{text}\"");
}
}
If I use a table collection name, the log is:
And using a GUID:
So oddly it seems that when using a name the table actually loads, even if getting the string fails.