Revert to SDLXLIFF

Dear community,

We are experiencing issues when we generate target files multiple times as part of our custom target XML validation check. Sometimes the target XMLs don't have text nodes.

As a work around, we would like to revert all XML files to SDLXLIFF before running batch task Generate Target Translations again. Is the Revert to SDLXLIFF method exposed via the API?

Best wishes,
Simon

Parents
  • In the meantime this snippet will do the trick:

    private static void RevertToSdlxliff(string projectPath)
    {
    var doc = XDocument.Load(projectPath);

    var targetLangs = doc.Descendants("LanguageDirections").First().Descendants("LanguageDirection").Select(d => d.Attribute("TargetLanguageCode").Value);

    var langFiles = doc.Descendants("LanguageFile").Where(f => targetLangs.Contains(f.Attribute("LanguageCode").Value));

    foreach (var langFile in langFiles)
    {
    var fileVersions = langFile.Elements("FileVersions").First().Elements("FileVersion");

    foreach (var fileVersion in fileVersions)
    {
    var fileName = fileVersion.Attribute("FileName").Value;

    if (!Path.GetExtension(fileName).Equals(".sdlxliff", StringComparison.InvariantCultureIgnoreCase))
    {
    fileVersion.Remove();
    Console.WriteLine("- Reverted {0}", fileName);
    }
    }
    }

    doc.Save(projectPath);
    }
  • Thanks, but this didn't work for me. The fileVersion.Remove(); did not remove it from the (saved) doc.
    I modified it to make it work (for me).

    private static void RevertToSdlxliff(string projectPath)
    {
    var doc = XDocument.Load(projectPath);
    var targetLangs = doc.Descendants("LanguageDirections").First().Descendants("LanguageDirection").Select(d => d.Attribute("TargetLanguageCode").Value);
    doc.Descendants("LanguageFile")
    .Where(f => targetLangs.Contains(f.Attribute("LanguageCode").Value))
    .Descendants("FileVersions")
    .Descendants("FileVersion")
    .Where(x => !x.Attribute("FileName").Value.EndsWith(".sdlxliff")).Remove();
    doc.Save(projectPath);
    }
Reply Children
No Data