Using String Tables from C++

I love the new StringTable asset, for dealing with localization. From within the editor, creating a new StringTable asset and using it is super simple.

However I also want to be able to refer to strings stored within the same table from C++, and it’s a little confusing.
The only “documentation” I managed to find is this PDF from a previous UE4 AnswerHub question.

I would really appreciate some help with these points:

  • Where is it expected that we should put LOCTABLE_FROMFILE_GAME?
  • What do we need to do to make the LOCTABLE_FROMFILE_GAME macro available? It claims to be undefined if I try to use it from C++
  • What is the .ini config that’s mentioned in the PDF? How do we use it?
  • If I define a StringTable in C++, will it be available in the editor? Do I have to do anything special?
1 Like

LOCTABLE_FROMFILE_GAME is for loading CSV string tables at runtime. The search root for finding the file is “{YourGame}/Content”, and you have to make sure that the CSV files are staged.

LOCTABLE_FROMFILE_GAME is defined in StringTableRegistry.h.

INI configs refers to setting a FText property in an INI file to reference a String Table entry via the LOCTABLE syntax, in the same way that you can use the NSLOCTEXT syntax to define a literal text value in an INI file.

Purely C++ and CSV file loaded String Tables will be available to reference in FText properties in the editor.

If you want to use an asset defined String Table in C++, then you can use its asset path as the key for the LOCTABLE macro. It looks something like “/Game/MyStringTable.MyStringTable” IIRC.

Thank such for replying so quickly, Jamie! It answers most of my questions, I just have a few follow-ups:

Where should I put LOCTABLE_FROMFILE_GAME in my C++, so it gets loaded and made available when the editor runs? I’m using the non-source version of the editor. Do I have to make a plugin?
Maybe I’m misunderstanding something, but I’d like the same stringtable I define in C++ to be visible in the editor. Do I have to create a UAsset from the same .CSV and use that in the editor?
I’ve attached a screenshot to explain what I’m expecting.


I’d call it during your game module init.

Sorry I’m still quite new at this, game module is ProjectName.cpp where I have IMPLEMENT_PRIMARY_GAME_MODULE because that produces compile errors? Or I have to create an editor module for my game for this?

Sorry for being a big dense about this ^^;

Ah, sorry, I forgot it just generates a stub by default.

So right now it’ll be just using FDefaultGameModuleImpl in IMPLEMENT_PRIMARY_GAME_MODULE. You’ll want to create a class deriving from that, change that macro to use it, override StartupModule for your derived class and then do the String Table stuff in there. You can just define this class inside the .cpp file.

Thanks again Jamie, I got it all working, and I wrote up how to do it in a blog post

Thanks, couple of points for your post.

In C++, you can use LOCTABLE in addition to FText::FromStringTable (the latter exists primarily to deal with non-literal values, which the macro can’t handle).

You also need to make sure that you stage your CSV file so that it works in a cooked game. The PDF file I linked before tells you which setting to change there.

Hello benhumphreys, i followed your blog post about the string tables and it worked just fine!
However when am trying to compile the c++ code from the unreal editor it gives me an error!
The weird thing is that although it crashes the editor when i reopen it it works fine until i edit anything in the c++ code and hit compile, first compile works, second = crash

Any ideas how to solve this?
error pic

Hi loel, I had the same problem and solved it with unregistering the table before loading it with FStringTableRegistry::Get().UnregisterStringTable.


LOCTABLE_FROMFILE_GAME("MyStrings", "MyStrings", "Assets/Strings/MyStringTable.csv");

I use the same ID “MyStrings” for both parameters, because otherwise the localisation dashboard has the same strings under two different namespaces. This also works while having the same csv file as an String Table asset in the editor.

I am still a bit unsure if that is an elegant solution…

I can confirm this works. Thank you, and also thanks to the original poster, benhumphreys!

I’ve also found a bug that the whole thing fails (Editor won’t have this string table, Loc Dashboard won’t gather text from it) if you have spaces in the path to your CSVs which is funny because by default your projects sit in …/Unreal Projects/ folder :smiley:

Thank you very much!!! This (FStringTableRegistry::Get().UnregisterStringTable(“MyStrings”):wink: very help me!

Thank you!!! It work. I love you