I would like to update my localized download contents without leaving the app running.
I think the following steps are needed to do this.
- Unload target tables
- Update the Addressables Catalog
- Re-initialize Localization
- Load the tables again
I have been able to test that the contents can be updated using the following script, but I am not confident that this is correct. In particular, the part that resets and reinitializes LocalizationSettings.
What is the correct way to update the download contents by Localization?
using System.Collections;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Localization.Settings;
using UnityEngine.UI;
namespace LocalizationTest
{
public class LocalizationContentsUpdateTest : MonoBehaviour
{
[SerializeField] private Button _button;
[SerializeField] private Text _text;
[SerializeField] private string _stringTableName = "ExampleStringTable";
[SerializeField] private string _stringEntryName = "ExampleStringEntry";
public void Awake()
{
_button.onClick.AddListener(OnClicked);
}
public void OnDestroy()
{
_button.onClick.RemoveListener(OnClicked);
}
private void OnClicked()
{
LogEntryValue();
}
private void LogEntryValue()
{
StartCoroutine(LogEntryValueRoutine());
}
private IEnumerator LogEntryValueRoutine()
{
// Update catalog.
var checkUpdatesHandle = Addressables.CheckForCatalogUpdates(false);
yield return checkUpdatesHandle;
var updates = checkUpdatesHandle.Result;
Addressables.Release(checkUpdatesHandle);
if (updates.Count >= 1)
Addressables.UpdateCatalogs();
// Reset initialization state.
LocalizationSettings.Instance.ResetState();
// Initialize LocalizationSettings.
yield return LocalizationSettings.InitializationOperation;
// Load table.
var handle = LocalizationSettings.StringDatabase.PreloadTables(_stringTableName);
yield return handle;
// Get entry.
var entry = LocalizationSettings.StringDatabase.GetTableEntry(_stringTableName, _stringEntryName).Entry;
if (_text != null)
_text.text = entry.Value;
// Release table.
LocalizationSettings.StringDatabase.ReleaseTable(_stringTableName);
}
}
}
Thanks!