Download Contents Update Workflow

I would like to update my localized download contents without leaving the app running.
I think the following steps are needed to do this.

  1. Unload target tables
  2. Update the Addressables Catalog
  3. Re-initialize Localization
  4. 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!

Hey.

This sounds correct. You need to make sure the tables are actually unloaded though.If you have any localized text in the scene at the time then they will still be loaded, all references need to be released. The best way to do this is to load an en empty scene.

We discussed reloading the addressables in this thread here (Case 1343032) Updating Localization through Addressables causes System.Exception

See their script CheckForCatalogUpdates method, this is what you need to do.

1 Like

Thanks for the immediate response.

You need to make sure the tables are actually unloaded though.
Yes, I understand. Thank you!

https://forum.unity.com/threads/cas...addressables-causes-system-exception.1125758/
I will also check this thread.

1 Like

Thanks

We will also look into how we can make this easier in the future, maybe add our own update method to do it automatically for you.

1 Like

That sounds so good!
Thanks!

1 Like