GetLocalizedStringSAsync - Multiple values

Hello!

Please advise how to implement this example:

    var data = LocalizationSettings.StringDatabase.GetLocalizedStringSAsync(tableId, "diff_easy","diff_medium","diff_hard","...");
   // or
    var data = LocalizationSettings.StringDatabase.GetLocalizedStringSAsync(tableId,new List<string>(){
        "diff_easy",
        "diff_medium",
        "diff_hard",
        "..."
    });

    data.Completed += (x) =>
    {
        var result = x.Result;
        for (int i = 0; i < result.Length; i++)
        {
            Debug.Log(result[i]);//"Easy" "Medium" "Hard"...
        }
    };

What is it you are trying to do? You want to display the contents of a list? Have you used the List Formatter?
https://docs.unity3d.com/Packages/com.unity.localization@1.2/manual/Smart/List-Formatter.html

Or are you trying to get multiple entries from a table at once?

I want to get multiple entries from a table at once.

So that I can do this…

   var data = LocalizationSettings.StringDatabase.GetLocalizedStringSAsync(tableId,new List<string>(){
        "diff_easy",
        "diff_medium",
        "diff_hard",    
    });

    data.Completed += (x) =>
    {
        var result = x.Result;
        for (int i = 0; i < result.Length; i++)
        {
          textMeshPros[i].text = result[i];
        }

      StartCoroutine(SetMinFontSize());
    };

        IEnumerator SetMinFontSize()
        {
            yield return new WaitForEndOfFrame();

            float minFontSize = textMeshPros[0].fontSize;
      
                for (int i = 0; i < textMeshPros.Length; i++)
                {
                    if (textMeshPros[i].fontSize < minFontSize)
                        minFontSize = textMeshPros[i].fontSize;
                }

                for (int i = 0; i < textMeshPros.Length; i++)
                {
                    textMeshPros[i].fontSizeMax = minFontSize;
                }            
        }

We don’t have an API to batch requests like this but you could get the table and query it yourself.

Instead of calling GetLocalizedString call
GetTable and then query the table to get each entry by calling GetEntry.

1 Like

I made it like this

   public static void GetLocStrings(string tableId, Action<List<string>> callback, params string[] keys)
    {
        var table = LocalizationSettings.StringDatabase.GetTableAsync(tableId);
        table.Completed += (x) =>
        {
            List<string> entries = new List<string>(keys.Length);

            var result = x.Result;

            for (int i = 0; i < keys.Length; i++)
            {
                var entry = result.GetEntry(keys);
                entries.Add(entry.Value);
            }

            if (callback != null)
            {
                callback(entries);
            }
        };
    }
1 Like