Skip to content

Instantly share code, notes, and snippets.

@andreaGhisa
Created October 25, 2018 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreaGhisa/e865c58b78f3fc5beb40b58de74b4c97 to your computer and use it in GitHub Desktop.
Save andreaGhisa/e865c58b78f3fc5beb40b58de74b4c97 to your computer and use it in GitHub Desktop.
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