Search Unity

Question Can we do this with a custom formatter?

Discussion in 'Localization Tools' started by dlorre, Nov 26, 2022.

  1. dlorre

    dlorre

    Joined:
    Apr 12, 2020
    Posts:
    699
    So I have this:

    Code (csharp):
    1.  
    2. "Time is {0} for white and {1} for black"
    3. "Time is {0} for both sides"
    4.  
    I know I can do it with 2 smart strings but I was wondering if I could write a custom formatter that could handle both cases. The second one is naturally for when black time == white time.
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    Possibly but I think you could also do it with a normal smart string.
    You could use a condition to pick either
    https://docs.unity3d.com/Packages/com.unity.localization@1.4/manual/Smart/Conditional-Formatter.html
     
    dlorre likes this.
  3. dlorre

    dlorre

    Joined:
    Apr 12, 2020
    Posts:
    699
    Yes I can do it with 3 parameters, I didn't figure out how to pass directly wtime==btime in the conditional statement.

    "Time is {0:{1} for both|{1} for white and {2} for black}"

    Code (csharp):
    1.  
    2.    label.text = messageFmt.GetLocalizedString( wtime==btime, wtime, btime);
    3.  
     
    karl_jones likes this.