Localized Strings Using StringTable and C++

Store localizable strings in a CSV file and use them in the editor and C++

Localization is a tricky issue in Unreal. All the tools are there, it's just a case of finding out how to use them. In this tutorial we will load localized strings from a central .csv file (also known as a StringTable), and use them in both the editor and C++.

Here is the general workflow we will follow

  1. Create a CSV (comma-separated values) file.
  2. Modify Game Module class in C++.
  3. Use our localized strings in C++ or the editor.

For the purposes of this example, our project is called MyProject.

1. Create a CSV File

Save it in your project's Content directory, anywhere you like. Remember this path,

For the purposes of this example, we will be saving ours as: MyProject/Content/Localization/UIStringTable.csv

UIStringTable.csv
Key,SourceString,Comment
HelloWorld,"Hello there, and welcome to the game!",Welcome message
QuitGameLabel,"Quit the Game",
LongDescription,"Welcome to the thing.

Here's multi-line text.",
ButtonLabel,"Click me",

A few points about .csv files in Unreal:

  • You can surround your strings with quotes, to let you use commas in your strings
  • If you use quotes, you can use new-lines in your strings
  • If you use quotes, you can use double-quotes to escape. e.g. "She said ""See ya!"" and left"

2. Modify our Game Module Class

In order for our String Table to be available from the editor, in drop-down menus, we need to load it when our Game Module gets loaded.

MyProject.h
#pragma once

#include "CoreMinimal.h"

class FMyProject : public FDefaultGameModuleImpl
{
public:
	virtual void StartupModule() override;
	virtual void ShutdownModule() override;
};
MyProject.cpp
#include "MyProject.h"
#include "Modules/ModuleManager.h"

#include "Internationalization/StringTableRegistry.h"
#include "Paths.h"

void FMyProject::StartupModule()
{
	FDefaultGameModuleImpl::StartupModule();

	LOCTABLE_FROMFILE_GAME("UIStrings", "AnyOldNamespace", "Localization/UIStringTable.csv");
}


void FMyProject::ShutdownModule()
{
	FDefaultGameModuleImpl::ShutdownModule();
}

IMPLEMENT_PRIMARY_GAME_MODULE( FMyProject, MyProject, "MyProject" );

3. Using Stringtable Values

Now we can use the strings in our .csv file when editing Blueprints from C++.

In C++

If we called our StringTable UIStrings like in the example above, we can load one of the strings with the following:

Using StringTable values from C++
// This returns "Hello there and welcome to the game!" in the language that we're playing in
FText::FromStringTable("UIStrings", "HelloWorld")

We can also edit and add new entries the CSV, and the values will be available in Unreal as soon as we save the file.

In the Editor

Any FText variables will be displayed with the dropdown shown in the screenshot.

Using StringTable values within the editor.

Further Reading