Importing a (localization) PO file using C++ (LocalizationCommandletTasks::ImportTextForTarget)

Hello,

I am trying to write a plugin to be used internally, to connect to an external API and automate some of the localization steps. I’m using LocalizationCommandletTasks::GatherTextForTargets() to gather text, which is communicated with an external API for localization, and the result is sent back into the plugin. The plugin then creates a PO file using LocalizationCommandletTasks::ExportTextForCulture, and the PO file is edited with translations. It has been successful up to this point. If I import the PO file manually using the localization dashboard, it is successful, so no issues up to this point.

However, I am having trouble getting LocalizationCommandletTasks::ImportTextForTarget to work - when I try to import the PO file, the function is successful (returns true) and there is nothing noteworthy in the logs. When the task is complete, I tried adding LocalizationCommandletTasks::CompileTextForTargets as well as FTextLocalizationManager::Get().RefreshResources(). However, the target is not updated in the Localization Dashboard (word count etc is the same, even after manually doing word count / compiling translation), and the localization preview in the editor (e.g. for a widget blueprint) displays a strange behavior: if I preview immediately after the tasks above, it displays the updated translation, but when I change the culture (with the globe button) back and forth, it goes back to the localization before the import.

Here is the code snippet that I’m working on:

// ... PO file is successfully created and edited
// TargetObject is ULocalizationTarget from ULocalizationSettings::GetGameTargetSet(). It is the correct target as I am only testing with one target (Game) in the project.
bool isImportSuccess = LocalizationCommandletTasks::ImportTextForTarget(Window.ToSharedRef(), TargetObject, PoPath); // This function always returns true, but is not reflected in the editor or the localization dashboard
if (!isImportSuccess)
{
	UE_LOG(LogTemp, Warning, TEXT("Failed to import PO file at: %s"), *PoPath);
	return;
}
LocalizationCommandletTasks::CompileTextForTarget(Window.ToSharedRef(), TargetObject);
FTextLocalizationManager::Get().RefreshResources(); // Doesn't seem to be effective.

Are there any additional steps I may have to take before/after the import? Or is this simply not a viable way to import a PO file with C++?

Apologies for the rather messy description. Let me know if I would need to provide other information. Any help and/or pointers are appreciated.

A small update: setting PO file importing aside, I had some success with working with LocRes files. In-engine preview seems to work well. However I’d still like to utilize importing PO files to better integrate with the Localization Dashboard (word count, compiling, etc. to better fit in with Unreal’s standard localization workflow).

Also, the “strange behavior” regarding preview strings popping on and off seems to have been a mistake from my part - I had mixed in code that deals with LocRes and that seems to have affected it. I’ve now separated processing LocRes files from dealing with PO files - and the LocRes function seems to work as expected.

Some things I forgot to mention in the original post:

  • I am not using revision control.
  • I am testing with 1 target (Game) and 1 culture (French “fr” for now), just to keep things simple for now.
  • Source strings are not being modified.

I noticed that there may be an additional step in the standard workflow using the Localization Dashboard, where after importing a PO file, there is an optional step to “Choose Translation”. I am also suspecting that there may be information passed onto the parent window, or some delegate that I have to handle. I am quite lost in this regard - any help would be appreciated!