public void UpdateText(IAsyncOCR OCRResult, TranslationCallback callback = null) { // Only reevaluate if the underlying text actually changed if (atrans == null || this.GetText(OCRResult) != this.atrans.rawText) { string NewText = GetText(OCRResult); BabelForm.Invoke(BabelForm.SafeIncrementOdometer, new object[] { 0, NewText.Length }); // Update odometer atrans = AsyncStatic.MakeTranslation(NewText, callback); } }
public static IAsyncTranslation MakeTranslation(string input, TranslationCallback callback) { switch (Properties.Settings.Default.TranslationDataSource) { case DataSource.Google: return(new GoogleImpl.AsyncTranslation(input, callback)); case DataSource.Microsoft: return(new MicrosoftImpl.AsyncTranslation(input, callback)); case DataSource.DeepL: return(new DeepLImpl.AsyncTranslation(input, callback)); default: return(new DummyImpl.AsyncTranslation(input, callback)); } }
public AsyncTranslation(string text, TranslationCallback callback = null) { rawText = text; this.callback = callback; if (text == null || text == "") { _translatedText = ""; _detectedLocale = Properties.Settings.Default.targetLocale; _timeStamp = "[empty]"; isDone = true; this.callback?.Invoke(this); } else { task = Task.Run(DoTranslation); } }
public PhraseRect(Rectangle Location, IAsyncOCR OCRResult, PhraseRectMode Mode, frmBabel BabelForm, TranslationCallback callback = null) { this.Location = Location; this.BabelForm = BabelForm; this.mode = Mode; if (Autofit) { DoAutoFit(OCRResult); } UpdateText(OCRResult, callback); }
public PhraseRect(Rectangle Location, IAsyncOCR OCRResult, frmBabel BabelForm, TranslationCallback callback = null) : this(Location, OCRResult, NewPhraseMode, BabelForm, callback) { // nothing to do }
public AsyncTranslation(string text, TranslationCallback callback) { rawText = text; callback?.Invoke(this); }