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
  3. Dismiss Notice

Question How to implement a gender localization shorthand like {g:He|She|They}

Discussion in 'Localization Tools' started by LazloBonin, Oct 23, 2023.

  1. LazloBonin

    LazloBonin

    Joined:
    Mar 6, 2015
    Posts:
    822
    Hi! I'm trying to implement a gender localization shorthand for our game.

    The obvious answer is to use the choose formatter like so, where "g" would be a gender num:

    Code (CSharp):
    1. {g:choose(Masculine|Feminine|Neutral):He|She|They}
    However, we use this very often, so this syntax is extremely verbose and error prone.

    Ideally, I'd want the syntax in the title:

    Code (CSharp):
    1. {g:He|She|They}
    Is there any way to implement this?

    I wasn't able to do it using custom sources (they don't support operators) nor custom formatters (they don't seem to support a function-less output).
     
  2. LazloBonin

    LazloBonin

    Joined:
    Mar 6, 2015
    Posts:
    822
    I've managed to implement a formatter based on the choose code that works for this syntax:

    Code (csharp):
    1. {:g():He|She|They}
    Is that the best I can hope for in terms of brevity?
     
  3. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,470
    Hi,
    If you find yourself repeatedly using the same argument in multiple places, creating a template is a practical solution. Here's how you can define a template:

    name: pronouns
    text: {{}:choose(Masculine|Feminine|Neutral):He|She|They}

    Please note the use of curly braces {} to reference the current value. To ensure this works correctly, make sure to enable "Alternative Escaping" in the Parser settings; otherwise, you might encounter complaints about the use of double curly braces {{}}.

    Then you can use it like so: g:t(pronouns)

    Your custom formatter appears well-constructed. In the future, if a translator or another team member needs to understand your code, including some context within the string, even if it makes it slightly longer, will greatly aid comprehension.
     
  4. LazloBonin

    LazloBonin

    Joined:
    Mar 6, 2015
    Posts:
    822
    Thanks for the tip!
    However I think you might have misunderstood the part I'm trying to shorten; I only wanna do away with the choose part (selector and format options, aka :choose(Masculine|Feminine|Neutral):), because the formats themselves (He|She|They) change on a case-by-case basis.

    Could I create a template like so?

    name: g
    text: {{}:choose(Masculine|Feminine|Neutral)}
    usage: g:He|She|They g:has|has|have an apple
     
  5. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,470
    Ah no I don't think you can do that with a template. I think the best you can do is the custom formatter you created {:g():He|She|They}
     
  6. LazloBonin

    LazloBonin

    Joined:
    Mar 6, 2015
    Posts:
    822
    Thanks for the confirmation, cheers!
     
    karl_jones likes this.