Search Unity

Nested LocalizedString by script

Discussion in 'Localization Tools' started by 5argon, Dec 22, 2021.

  1. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    Hello, I would like to set argument from C# script so that it is equivalent to choosing "Localized String" argument type in editor. When I tried this (put the LocalizedString object on the right side while using Dictionary Source), looks like it just use a ToString of LocalizedString instead of really resolving the text recursively. What is the correct syntax to do it from script?

    upload_2021-12-22_18-20-38.png


    upload_2021-12-22_18-24-9.png

    Desired settings that is possible from Editor :

    upload_2021-12-22_18-21-57.png
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    Nested strings are not supported when added to the Arguments field. Those are for normal scripting arguments, such as the type that you would use with String.Format. To support nested strings they need to be added as persistent arguments. You can use a LocalizedString like a dictionary for this.
    Try
    Code (csharp):
    1. headerString.StringReference["itemName"] = itemNameString;
     
    5argon likes this.
  3. collinpatrick15

    collinpatrick15

    Joined:
    Nov 7, 2018
    Posts:
    38
    Apologies for reviving an old thread, but this is related.

    This method works, however, I noticed the nested string is always empty the first time the parent string is retrieved. When I call it a second time it populates correctly.

    For example, I am trying to append the name of an effect to the name of a weapon. The parent string is
    "Old Staff of {EffectName}"

    and the nested effect name string is
    "Healing"

    The first time I call GetLocalizedStringAsync on the parent string, I am given
    "Old Staff of"

    and the second time is
    "Old Staff of Healing"

    I also noticed when I was logging the strings to the console that if I retrieve the effect name string first, separate from the parent, the parent will format correctly the first time it gets retrieved.

    Is this an intended behavior? I assume I am missing something pretty simple here. I am using version 1.3.2 of the localization package if that helps at all.
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    Hi,
    Could you try updating to 1.4.3? You may need to manually edit the manifest.json file in the packages folder if it does not show in the package manager. If the issue still happens then please file a bug report. I suspect its still waiting for the nested table to load, setting it to preload may work as a workaround for the moment.
     
  5. collinpatrick15

    collinpatrick15

    Joined:
    Nov 7, 2018
    Posts:
    38
    Sorry for the delay. I manually changed the package version to 1.4.3 and the issue still occurs. From my testing, your suspicions seem to be correct since it displays properly if I do something else that causes the nested string table to load first. Is there a specific place I can file the bug report for the localization package, or do I just go through the generic bug reporter in the editor?
     
  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    Using the normal bug reporter is the correct procedure. Thanks