Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Bug Cannot substitute multiple values

Discussion in 'Localization Tools' started by syjgin, Oct 16, 2020.

  1. syjgin

    syjgin

    Joined:
    Feb 13, 2015
    Posts:
    137
    https://stackoverflow.com/questions...ns-generic-list1system-string-instead-of-data got same result while trying to fill smart string with multiple values (tried strings and enum values).
    String:
    Excellent. We are moving, but too slow. This is good for maneuvers, but to get anywhere faster, you need to accelerate. Press {0} to increase speed. You can also decrease speed with {0} and switch speeds with the mouse
    Code to display text:
    Code (CSharp):
    1. _replicText.text = Smart.Format(result, keyCodes);
    where keycodes is List of KeyCode objects. But with list of string I got same result. With smart library list formatting https://github.com/axuno/SmartFormat/wiki/Lists all works fine, but what can I do if I want to insert array elements into different parts of string?
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,410
    Did you try passing the list as an argument in a list?
    Like the example:
    Code (csharp):
    1. _replicText.text = Smart.Format(result,  new object[] { keyCodes });
     
  3. syjgin

    syjgin

    Joined:
    Feb 13, 2015
    Posts:
    137
    no effect:
    upload_2020-10-17_9-0-41.png
     
  4. syjgin

    syjgin

    Joined:
    Feb 13, 2015
    Posts:
    137
    The walkaround is to pass array elements individual, but not whole array as argument:
    Text:
    Excellent. We are moving, but too slow. This is good for maneuvers, but to get anywhere faster, you need to accelerate. Pressing will increase {0}, {1} will decrease the speed. You can also switch speeds with the mouse

    Code (CSharp):
    1. if (keyCodes.Count == 0)
    2.                 {
    3.                     _replicText.text = result;
    4.                 }
    5.                 //TODO: rewrite this
    6.                 else if(keyCodes.Count == 1)
    7.                 {
    8.  
    9.                     _replicText.text = Smart.Format(result, keyCodes[0]);
    10.                 }
    11.                 else if(keyCodes.Count == 2)
    12.                 {
    13.  
    14.                     _replicText.text = Smart.Format(result, keyCodes[0], keyCodes[1]);
    15.                 }
    16.                 else {
    17.                     _replicText.text = Smart.Format(result, keyCodes);
    18.                 }
    Maybe, this is not related to localization, but for Smart library itself. Maybe, I just using it wrongly, and there are proper way for use array elements in multiple places on the string exists
     
  5. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,410
    Oh I see. You want the individual elements from the array. Doing {0} etc will treat it like a normal String.Format argument.

    I'll have a closer look on Monday to see if it's possible. You can always create a custom source if it's not.

    Edit: I just noticed you are using Smart. How are you fetching the strings? Have you tried passing the arguments in when you get the values instead of directly using Smart?

    Code (csharp):
    1. LocalizationSettings.StringDatabase.GetLocalizedStringAsync("General Test Data", "Test", new object[] { KeyCode.A, KeyCode.LeftShift });
     
    Last edited: Oct 19, 2020