Setting Arguments in script to be equivalent to LocalizedString Local Variable

In Local Variables I could nest LocalizedString as a variable :

How could I do the same via setting .Arguments in scripting? Supposed that I have got :

[SerializeField] private LocalizedString itemNames;
[SerializeField] private LocalizeStringEvent amountTextLocalizeStringEvent;

Then by simply using the LocalizedString variable as the value of the dictionary does not work, it seems to use the .ToString() of LocalizedString instead. Looks like this : “TableReference(f3c84191-d489-64d4-5b53-f8d09cdff06d - Item)/TableEntryReference(3405916397627 - MyItem/Name)”

            amountTextLocalizeStringEvent.StringReference.Arguments = new object[]
            {
                new Dictionary<string, object>
                {
                    ["variable"] = itemNames,
                }
            };

I get that I could itemNames.GetLocalizedStringAsync() and then simply put in the resulting string instead of nesting, but it need some async routine to prepare instead of letting localization package resolve the async chain for me if I could nest it.

You want to set the local variables included nested strings by script?
You can do like this:

https://docs.unity3d.com/Packages/com.unity.localization@1.0/api/UnityEngine.Localization.LocalizedString.html#UnityEngine_Localization_LocalizedString__ctor

public LocalizedString withNestedTranslation = new LocalizedString("My String Table", "My Game Text")
{
   { "some-text", new StringVariable { Value = "Hello World" } },
   { "nested", new LocalizedString("My String Table", "My Nested Text")
     {
         { "score", new IntVariable { Value = 100 } },
     }}
};

You can add and remove local variables.

1 Like

Thank you, .StringReference.Add works!

It seems like the 2 approach (.Arguments or .Add) are slightly different and .Add has IVariable interface that make it understand nested LocalizedString. At first I was avoiding using .Add in script because it says it would be persistent instead of not serialized like .Arguments and I would not want script to make persistent change.

Oh yes. Arguments are more like the String.Format arguments. If you want to use names then they need to go in the persistent variables. Arguments can only be accessed using the index of the position they are at.