Using variables to initialize FText with namespace and key

I want to initialize FText from variables. The NSLOCTEXT() macro only allows string literals.

FName identifier = TEXT("MyIdentifier");
// Does not work for obvious reasons:
FText ident = NSLOCTEXT("MyNamespace", "MyKey", *identifier.ToString());
// Though the content is set, no namespace/keys are set:
FText ident = FText::Format(NSLOCTEXT("MyNamespace", "MyKey", "{0}"), FText::FromName(identifier));

For now I’m using the method of the NSLOCTEXT() macro

FText ident = FInternationalization::ForUseOnlyByLocMacroAndGraphNodeTextLiterals_CreateText(*identifier.ToString(), TEXT("MyNamespace"), *identifier.ToString());

which works, but as the method name already says, it is not intended for such usage.
Are there other macros/methods available to initialize FText with variables instead of literals?

Hi Roi,

I use FText::ChangeKey(NewNamespace, NewKey, InText);.

Hope that helps. Cheers,

Though ChangeKey is not semantically correct when initializing new FText() vars, this method is part of the documented FText API and is way better readable than what I used above. Thanks a lot!

Btw, example for usage with same FName for key and value:

FName identifier = TEXT("MyIdentifier");
FText localizedIdentifier = FText::ChangeKey(TEXT("MyNamespace"), identifier.ToString(), FText::FromName(identifier));

ChangeKey is an editor only function. So this is pretty useless for packaged builds, unless you want to package editor code.