How to update existing ProjectFile in FileBasedProject incrementally

I would like to update existing file in project incrementally without recreating project.

For example, project contains 3 files(A, B, C) then I would like to update only A.

When i execute ConvertToTranslatableFormat again, sdlxliff for source language is created correctly, but CopyToTargetLanguages is failed.

e.g.
AutomaticTask convertTask = project.RunAutomaticTask( currentFileId, AutomaticTaskTemplateIds.ConvertToTranslatableFormat);
AutomaticTask copyTask = project.RunAutomaticTask(currentFileId,AutomaticTaskTemplateIds.CopyToTargetLanguages);


If I assume that we can delete a file in project fisrt then run Scan, ConvertToTranslatableFormat and CopyToTargetLanguages, we can update specified file in project without recreating project.
But according to following URL, delete feature is not supportd.
https://community.sdl.com/developers/language-developers/f/57/t/4668#pi239031345filter=all&pi239031345scroll=false

Is there any solution to update existing file in project ?

Parents
  • Former Member
    0 Former Member

    I came across this kind of issue for a workflow automation, and managed to implement the following workaround:

    // Declare your XML document here, loading the .SDLPROJ file
    XmlDocument pfile = new XmlDocument(); pfile.Load(project.FilePath); XPathNavigator pnav = pfile.CreateNavigator();
    // Iterate over Language File IDs - obviously the code below is nested in a for() loop XPathExpression xpr = pnav.Compile(@"//LanguageFile[@Guid='" + tfiles[incr].Id + "']"); foreach (XPathNavigator node in pnav.Select(xpr)) { node.DeleteSelf(); }
    // Save the .SDLPROJ file pfile.Save(project.FilePath);
    // "Physically" delete the target .SDLXLIFF file File.Delete(tfiles[incr].LocalFilePath);

     Where tfiles is declared this way:

    ProjectFile[] tfiles = project.GetTargetLanguageFiles();

     It is strongly recommended (read: DO IT) that you save your project first and nest this into a try {} catch {} before saving your modifications!

Reply
  • Former Member
    0 Former Member

    I came across this kind of issue for a workflow automation, and managed to implement the following workaround:

    // Declare your XML document here, loading the .SDLPROJ file
    XmlDocument pfile = new XmlDocument(); pfile.Load(project.FilePath); XPathNavigator pnav = pfile.CreateNavigator();
    // Iterate over Language File IDs - obviously the code below is nested in a for() loop XPathExpression xpr = pnav.Compile(@"//LanguageFile[@Guid='" + tfiles[incr].Id + "']"); foreach (XPathNavigator node in pnav.Select(xpr)) { node.DeleteSelf(); }
    // Save the .SDLPROJ file pfile.Save(project.FilePath);
    // "Physically" delete the target .SDLXLIFF file File.Delete(tfiles[incr].LocalFilePath);

     Where tfiles is declared this way:

    ProjectFile[] tfiles = project.GetTargetLanguageFiles();

     It is strongly recommended (read: DO IT) that you save your project first and nest this into a try {} catch {} before saving your modifications!

Children