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.