Search Unity

Download Contents Update Workflow

Discussion in 'Localization Tools' started by Harumak, Mar 2, 2022.

  1. Harumak

    Harumak

    Joined:
    May 25, 2017
    Posts:
    6
    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?

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3. using UnityEngine.AddressableAssets;
    4. using UnityEngine.Localization.Settings;
    5. using UnityEngine.UI;
    6.  
    7. namespace LocalizationTest
    8. {
    9.     public class LocalizationContentsUpdateTest : MonoBehaviour
    10.     {
    11.         [SerializeField] private Button _button;
    12.         [SerializeField] private Text _text;
    13.         [SerializeField] private string _stringTableName = "ExampleStringTable";
    14.         [SerializeField] private string _stringEntryName = "ExampleStringEntry";
    15.  
    16.         public void Awake()
    17.         {
    18.             _button.onClick.AddListener(OnClicked);
    19.         }
    20.  
    21.         public void OnDestroy()
    22.         {
    23.             _button.onClick.RemoveListener(OnClicked);
    24.         }
    25.  
    26.         private void OnClicked()
    27.         {
    28.             LogEntryValue();
    29.         }
    30.  
    31.         private void LogEntryValue()
    32.         {
    33.             StartCoroutine(LogEntryValueRoutine());
    34.         }
    35.  
    36.         private IEnumerator LogEntryValueRoutine()
    37.         {
    38.             // Update catalog.
    39.             var checkUpdatesHandle = Addressables.CheckForCatalogUpdates(false);
    40.             yield return checkUpdatesHandle;
    41.             var updates = checkUpdatesHandle.Result;
    42.             Addressables.Release(checkUpdatesHandle);
    43.             if (updates.Count >= 1)
    44.                 Addressables.UpdateCatalogs();
    45.  
    46.             // Reset initialization state.
    47.             LocalizationSettings.Instance.ResetState();
    48.            
    49.             // Initialize LocalizationSettings.
    50.             yield return LocalizationSettings.InitializationOperation;
    51.  
    52.             // Load table.
    53.             var handle = LocalizationSettings.StringDatabase.PreloadTables(_stringTableName);
    54.             yield return handle;
    55.  
    56.             // Get entry.
    57.             var entry = LocalizationSettings.StringDatabase.GetTableEntry(_stringTableName, _stringEntryName).Entry;
    58.  
    59.             if (_text != null)
    60.                 _text.text = entry.Value;
    61.  
    62.             // Release table.
    63.             LocalizationSettings.StringDatabase.ReleaseTable(_stringTableName);
    64.         }
    65.     }
    66. }
    67.  
    Thanks!
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,293
    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 https://forum.unity.com/threads/cas...addressables-causes-system-exception.1125758/

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

    Harumak

    Joined:
    May 25, 2017
    Posts:
    6
    karl_jones likes this.
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,293
    Harumak likes this.
  5. Harumak

    Harumak

    Joined:
    May 25, 2017
    Posts:
    6
    That sounds so good!
    Thanks!
     
    karl_jones likes this.