Daily Unreal Column #81 - Plural variants for string format
When creating user facing interface with text, one of the annoying things in terms of creating a logic is making sure that we update the text labels based on the number. Here is how to make it easy.
Format Text
node has a hidden logic that allows us to define different plural forms based on a number we use. Here is syntax for it:
{Parameter}|plural(one=Text,other=OtherText)
Let’s break it down. First, we must specify a parameter that will be used to evaluate which form the Format Text
node should use. Right after that, we must insert |
and specify the function (I guess?) name, in this case, plural
. Then, inside paranthesis, specify version for a single item with one=YourText
and finally specify version for all the other cases by typing other=YourOtherText
.
Example usage:
{Num}|plural(one=item,other=items)
Here is a blueprint graph presenting the above example:
With the literal int value equal to 1, the above format text would evaluate to “You have 1 item.”. If we were to change it to any other value greater than 1, we would get “You have X items.”.
Readers should take care when dealing with localization and plurality. Pluralization is a tricky topic for some languages as you don't have just "single / plural" form of words, but you need to have "Zero / One / Two / Few / Many / Other" to cover most languages. Luckily FormatText supports all of these (see Internationalization\TextFormatArgumentModifier.cpp) but you still need to take it into account when localizing.
You might notice that most AAA games don't even bother, and all instances of user-facing text where you receive a certain amount of anything will instead be in the form of "Singular xCount", like "Sword x2" and "Potion x10". This is usually what I recommend UX designers to do for game projects.