protected override void ExecuteCore() { string sourcePath = XlfFile.GetMetadataOrThrow(MetadataKey.XlfSource); string sourceFormat = XlfFile.GetMetadataOrThrow(MetadataKey.XlfSourceFormat); string language = XlfFile.GetMetadataOrThrow(MetadataKey.XlfLanguage); string translatedFullPath = XlfFile.GetMetadataOrThrow(MetadataKey.XlfTranslatedFullPath); TranslatableDocument sourceDocument = LoadSourceDocument(sourcePath, XlfFile.GetMetadata(MetadataKey.XlfSourceFormat)); XlfDocument xlfDocument = LoadXlfDocument(XlfFile.ItemSpec); bool validationFailed = false; xlfDocument.Validate(validationError => { validationFailed = true; Log.LogErrorInFile(XlfFile.ItemSpec, validationError.LineNumber, validationError.Message); }); IReadOnlyDictionary <string, string> translations = validationFailed ? new Dictionary <string, string>() : xlfDocument.GetTranslations(); sourceDocument.Translate(translations); Directory.CreateDirectory(Path.GetDirectoryName(translatedFullPath)); sourceDocument.RewriteRelativePathsToAbsolute(Path.GetFullPath(sourcePath)); sourceDocument.Save(translatedFullPath); }
private static List <XmlSchemaException> GetValidationErrors(XlfDocument document) { var validationErrors = new List <XmlSchemaException>(); Action <XmlSchemaException> exceptionHandler = e => validationErrors.Add(e); document.Validate(exceptionHandler); return(validationErrors); }