Download

Edit FTexts in Defaults Panels

I’m currently experimenting with FTexts and localization support in Unreal Engine 4. What I want to achieve is having a localizable display name for each level, editable through the Level Blueprint’s defaults panel. For this I made a class inheriting from ALevelScriptActor:


/**
 * Cusotm level blueprint override
 */
UCLASS(BlueprintType, Blueprintable, HideCategories=(Replication, Input, Actor, Tags))
class CUSTOMENGINE_API ACustomLevelScriptActor : public ALevelScriptActor
{
	GENERATED_UCLASS_BODY()

	/** This level's display name */
	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category=LevelSettings)
	FText LevelName;
};


ACustomLevelScriptActor::ACustomLevelScriptActor(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	this->LevelName = NSLOCTEXT("Level Names", "Default Level Name", "New Level");
}

In UE4 Editor, that code will look like this:

e71dba1ed02b65ad6a74edc3e7a649750119551b.png

As you can see I edited the level name from “New Level” to “First Level” here for testing purposes. Now I extracted the localization files from the project using the commandlet. Surprisingly this worked just fine. However, there is one problem. With the FTexts edited through the defaults panel, UE4 fills namespaces and keys of FTexts automatically. For the keys this isn’t much of a problem, I suppose, since UE4 seems to only use the keys internally, anyways. For the namespaces this could become quite bugging, though. UE4 automatically puts those FTexts into the default namespace, so if you have a lot of text in your game it could become quite confusing and unorganised sooner or later. Take a look at this:


{
	"Namespace": "",
	"Children": 
		{
			"Source":
			{
				"Text": "First Level"
			},
			"Translation":
			{
				"Text": "First Level"
			}
		},
		{
			"Source":
			{
				"Text": "Second Level"
			},
			"Translation":
			{
				"Text": "Second Level"
			}
		}
	],
	"Subnamespaces": 
		{
			"Namespace": "Level Names",
			"Children": 
				{
					"Source":
					{
						"Text": "New Level"
					},
					"Translation":
					{
						"Text": "New Level"
					}
				}
			]
		}
	]
}

This is what the extracted archive file looks like. Now I would love to have all level names grouped together in the “Level Names” namespace here and I would love to have a clean and practical solution for this. As far as I know you can specify keys and namespaces yourself when creating FTexts from blueprint, but I don’t want to force map designers to add a Blueprint to each of their levels. So my question is this: Is it possible at all to force the namespace of that FText to a certain value without using any blueprint code? Maybe using some kind of meta data specifier? Or do I have to do that manually by overriding PostEditChangeProperty()? Would that work at all? Would I have to change that property to an FString for this and only use an FTtext internally? Or won’t any of that work at all and I do have to go with the blueprint method after all?

Thanks in advance!

Hello,
I have the same problem, Did you find any solution for this?
I have a lot of blueprint classes with TArray<FText> inside them and all the texts are generated into an empty namespace, the most annoying of this is that even inside the empty namespace the Texts are stored unordered (not in the same order as inside the TArray)
I need help with this.
Sorry for my bad english :slight_smile: