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

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:

{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:

{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).

I’ve managed to implement a formatter based on the choose code that works for this syntax:

{:g():He|She|They}

Is that the best I can hope for in terms of brevity?

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:

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.

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?

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

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}

Thanks for the confirmation, cheers!

1 Like