public FileReader(IEnumerable <ITranslationProviderLanguageDirection> tms, FinetuneBatchTaskSettings settings, int collectedSentencePairCount) { this.CollectedSentencePairCount = collectedSentencePairCount; this.settings = settings; this.FileTranslations = new List <Tuple <string, string> >(); this.FileNewSegments = new List <string>(); this.TmFuzzies = new List <TranslationUnit>(); this.tmLanguageDirections = tms; this.sourceVisitor = new FiskmoMarkupDataVisitor(); this.targetVisitor = new FiskmoMarkupDataVisitor(); }
//This function starts translating all segments in the document once the document is opened, //so that the translator won't have to wait for the translation to finish when opening a segment. //Note that Studio contains a feature called LookAhead which attempts to do a similar thing, but //this feature appears to be buggy with TMs etc., so it's better to rely on a custom caching system. private static void TranslateDocumentSegments(Document doc, LanguageDirection langPair, FiskmoOptions options) { var visitor = new FiskmoMarkupDataVisitor(); EditorController editorController = SdlTradosStudio.Application.GetController <EditorController>(); foreach (var segmentPair in doc.SegmentPairs) { if (segmentPair.Properties.ConfirmationLevel == Sdl.Core.Globalization.ConfirmationLevel.Unspecified) { visitor.Reset(); segmentPair.Source.AcceptVisitor(visitor); var sourceText = visitor.PlainText; var sourceCode = langPair.SourceLanguage.CultureInfo.TwoLetterISOLanguageName; var targetCode = langPair.TargetLanguage.CultureInfo.TwoLetterISOLanguageName; var langpair = $"{sourceCode}-{targetCode}"; //This will generate the translation and cache it for later use FiskmöMTServiceHelper.Translate(options, sourceText, sourceCode, targetCode, options.modelTag); } } processedDocuments[langPair].Add(doc); }