Search Unity

SmartFormat does not format nested conditional

Discussion in 'Localization Tools' started by julcreutz, Jan 3, 2022.

  1. julcreutz

    julcreutz

    Joined:
    May 4, 2021
    Posts:
    21
    The following string is not being formatted by SmartFormat.

    Code (CSharp):
    1. {0:If |}{1:{2:{}|, | or }|{2:{}|, | and }}{0: ...|}
    The exception:

    Code (CSharp):
    1. The format string has 1 issue:
    2. Format string is missing a closing brace
    3. In: "{0:If |}{1:{2:{}|, | or }|{2:{}|, | and }}{0: ...|}"
    4. At:  ---------------------------------------------------^
    Even tough, obviously, no closing brace is missing.

    Taking out the second conditional parameter in the nested conditional resolves the exception.

    Code (CSharp):
    1. {0:If |}{1:{2:{}|, | or }|exception}{0: ...|}
    I'm fairly certain the string I want to format is valid syntax. Why is not working then? Is this a bug of SmartFormat?
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,288
    Try enabling alternative escape in the smart format settings. It's because you have }}.
     
  3. julcreutz

    julcreutz

    Joined:
    May 4, 2021
    Posts:
    21
    Awesome, this fixed it! Should have looked into the settings.
     
    karl_jones likes this.