How can I Concatenate FText Together?

Dear Friends at Epic?

I see the FTextBuilder

but it is converting from FString and its internal data type is FString.

Epic released article stating you should not convert FString to FText, and should use NSLOCTEXT instead.

with FString I can do

FString HowIFeelToday = FString("Happy") + FString(" ") + FString("Today");

So.

How do I concatenate FText?

I am trying to do this:

FText Health 	=	NSLOCTEXT("Solus","Solus","HP ") + FText::AsNumber(SaveDetails.PlayerHealth);

or this

FText DayCount 	=	NSLOCTEXT("Solus","Solus","Day ") + FText::AsNumber(SaveDetails.DayCount);

Thanks!

Rama

You probably want one of the FText::Format family of functions.

These take a FText as the formatting string, which allows for localisation to re-order the arguments if required for the current language.

The first string needs to be a format specifier, you can also include text in this if you need to (just like with printf formatting), so you probably want something like this (the syntax is more like the Python str.format style to support re-ordering for localisation):

FText::Format(NSLOCTEXT("Solus","DayFmt","{0} {1}"), NSLOCTEXT("Solus","Solus","Day"), FText::AsNumber(DayCount)); // takes both as arguments
FText::Format(NSLOCTEXT("Solus","Solus","Day {0}"), FText::AsNumber(DayCount)); // takes just the day number and formats it into the Day string

#Thank You Jamie!

Oooh wow! I read the whole Ftext class and looked at format and did not think that could mean Concatenate.

#Please Correct Text.h

Your comment to me should be in the code itself!

like so

/*These take a FText as the formatting string, 
*   which allows for localisation to re-order the arguments if required for 
*      -Jame Dale Who is Awesome
*/
static FText Format(const FText& Fmt,const FText& v1);
static FText Format(const FText& Fmt,const FText& v1,const FText& v2);
static FText Format(const FText& Fmt,const FText& v1,const FText& v2,const FText& v3);
static FText Format(const FText& Fmt,const FText& v1,const FText& v2,const FText& v3,const FText& v4);

#My Final Code

My final result:

//These take a FText as the formatting string, 
//		which allows for localisation to re-order the arguments if required for the current language. -Jamie
DayCount = FText::Format(NSLOCTEXT("Solus","Solus","Day "), FText::AsNumber(SaveDetails.DayCount));

Health = FText::Format(NSLOCTEXT("Solus","Solus","HP "), FText::AsNumber(SaveDetails.PlayerHealth));

You can also do the formatting as key->value pairs of formatting arguments:

FFormatNamedArguments Args;
Args.Add("DayCount", DayCount);
FText::Format(NSLOCTEXT("Solus","Day","Day {DayCount}"), Args);

Or alternatively, as an array of arguments:

FFormatOrderedArguments Args;
Args.Add(DayCount);
FText::Format(NSLOCTEXT("Solus","Day","Day {0}"), Args);

Is there a way to do this with text variables in blueprint? I’m concerned about localization and the only node I can find to do this converts it to a string (the Append node).

Yes, the “Format Text” node is equivalent to FText::Format. You just put your arguments within { and }, and then they get added as input pins to the node.