Hello,
I added new file type to Project Template - AkomoNtoso XML which is recognized by "Any of the following root elements: akomoNtoso" and by "File dialog wildcard expression: *.xmlAco". Generally speaking the source files have xmlAco extension and are xml akomoNtoso files.
When I create the project manually by STUDIO, adding the files and then merging them everything works fine, but when I am trying to do the same via API I get "One or more files not supported." Exception from GetConverterToDefaultBilingual method. Is it another API bug or we just do not know how to use the API in a such complex operation?
Please find below the piece of code responsible for merging files.
One thing: before I merge, I load Project Template and I scan all documents. I noticed similar behaviour in Studio then adding files.
Code found here -> http://producthelp.sdl.com/SDK/ProjectAutomationApi/2017/html/721b3f8e-80b0-462f-864a-e284e3bfb70b.htm
and here-> https://romuluscrisan.com/merge-files-using-sdl-studio-project-automation-api/
My code below:
private ProjectFile[] MergeFiles(FileBasedProject StudioProject, Guid[] fileIds, string masterFileName)
{
if (StudioProject == null)
{
GlobalSettings.Log.WriteDetailsToLog("FileBaseProject variable is null", "", CategoryType.NotDefined, DetailsType.Less);
return null;
}
if (fileIds==null || fileIds.Length == 0)
{
GlobalSettings.Log.WriteDetailsToLog("fileIds is null", "", CategoryType.NotDefined, DetailsType.Less);
return null;
}
var pi = StudioProject.GetProjectInfo();
if (String.IsNullOrEmpty(masterFileName))
{
masterFileName = "master.sdlxliff";
}
StudioProject.SetFileRole(fileIds, FileRole.Translatable);
string pathInProject = string.Empty;
var mergedFile = StudioProject.CreateMergedProjectFile(masterFileName, pathInProject, fileIds);
//get the default file type manager which is needed to generate the bilingual files
var fileTypeManager = DefaultFileTypeManager.CreateInstance(true);
fileTypeManager.SettingsBundle = StudioProject.GetSettings();
//get the local file paths for the files that we want to merge
var filePaths = new string[mergedFile.ChildFiles.Length];
for (var i = 0; i < mergedFile.ChildFiles.Length; i++)
{
filePaths[i] = mergedFile.ChildFiles[i].LocalFilePath;
}
//get the default file converter to bilingual files
var converter = fileTypeManager.GetConverterToDefaultBilingual(filePaths, mergedFile.LocalFilePath, pi.SourceLanguage.CultureInfo, null,
(source, e) => GlobalSettings.Log.WriteDetailsToLog("Error creating merge file:" + e.Level.ToString() + e.Message,
"",
CategoryType.NotDefined,
DetailsType.Less)
);
//generate the bilingual file
converter.Parse();
//update the merge strucutre and the project
StudioProject.AddNewFileVersion(mergedFile.Id, mergedFile.LocalFilePath);
StudioProject.Save();
if (File.Exists(mergedFile.LocalFilePath))
{
ReplaceSourceLangueXML(mergedFile.LocalFilePath, pi.SourceLanguage.CultureInfo);
}
else
{
GlobalSettings.Log.WriteDetailsToLog("Merge file not generated!!!" + mergedFile.LocalFilePath, DetailsType.Less);
}
return StudioProject.GetSourceLanguageFiles();
}
Thank you for your help!