Created
October 25, 2018 10:09
-
-
Save andreaGhisa/e865c58b78f3fc5beb40b58de74b4c97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var converter = manager.GetConverterToDefaultBilingual(file.LocalFilePath, file.LocalFilePath, null); | |
var contentProcessor = new MtComparisonTargetContentProcessor(file.Language.IsoAbbreviation, file.Name, enName); | |
converter.AddBilingualProcessor(new BilingualContentHandlerAdapter(contentProcessor)); | |
converter.Parse(); | |
var segments = contentProcessor.CustomSegments; | |
public class MtComparisonTargetContentProcessor : AbstractBilingualContentProcessor | |
{ | |
private readonly string _targetLanguage; | |
private readonly string _fileName; | |
private readonly string _engineName; | |
public List<CustomSegment> CustomSegments { get; set; } | |
public MtComparisonTargetContentProcessor(string targetLanguage, string fileName,string engineName) | |
{ | |
_targetLanguage = targetLanguage; | |
_fileName = fileName; | |
_engineName = engineName; | |
CustomSegments = new List<CustomSegment>(); | |
} | |
public override void ProcessParagraphUnit(IParagraphUnit paragraphUnit) | |
{ | |
base.ProcessParagraphUnit(paragraphUnit); | |
if (paragraphUnit.IsStructure) { return; } | |
foreach (var segmentPair in paragraphUnit.SegmentPairs) | |
{ | |
var segmentVisitor = new SegmentVisitor(); | |
var sourceText = segmentVisitor.GetPlainText(segmentPair.Source); | |
var targetText = segmentVisitor.GetPlainText(segmentPair.Target); | |
var customSegment = new CustomSegment | |
{ | |
SegmentId = segmentPair.Properties.Id.Id, | |
SourceText = sourceText, | |
Translation = targetText, | |
FileName = _fileName, | |
EngineName = _engineName, | |
TargetLanguage = _targetLanguage | |
}; | |
segmentPair.Target.Clear(); | |
segmentPair.Target.Properties.ConfirmationLevel = ConfirmationLevel.Unspecified; | |
segmentPair.Target.Properties.TranslationOrigin = null; | |
CustomSegments.Add(customSegment); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment