private async void TranslateFromAllButton_Click(object sender, RoutedEventArgs e) { ResultBox.Text = string.Empty; string translateTo = documentTranslation.SelectedTargetLanguage; TranslationServices.Core.TranslationServiceFacade.ContentType contentType = TranslationServices.Core.TranslationServiceFacade.ContentType.plain; if (documentTranslation.SourceLanguageList.IndexOf(documentTranslation.SelectedTargetLanguage) == 0) { translateTo = "en"; } else { translateTo = TranslationServices.Core.TranslationServiceFacade.LanguageNameToLanguageCode(translateTo); } if (documentTranslation.TranslateModeList.IndexOf(documentTranslation.SelectedTranslateMode) == 1) { contentType = TranslationServices.Core.TranslationServiceFacade.ContentType.HTML; } Business.TranslateFromAll translateFromAll = new Business.TranslateFromAll(); translateFromAll.OneTranslationDone += TranslateFromAll_OneTranslationDone; Task <string> task = translateFromAll.TranslateFromAllLanguagesString ( InputBox.Text, translateTo, TranslationServices.Core.TranslationServiceFacade.CategoryID, contentType ); try { ResultBox.Text = await task; } catch (Exception ex) { ResultBox.Text = ex.Message; } }
private async void Button_Click(object sender, System.Windows.RoutedEventArgs e) { ResultBox.Text = string.Empty; string translateFrom = documentTranslation.SelectedSourceLanguage; TranslationServices.Core.TranslationServiceFacade.ContentType contentType = TranslationServices.Core.TranslationServiceFacade.ContentType.plain; if (documentTranslation.SourceLanguageList.IndexOf(documentTranslation.SelectedSourceLanguage) == 0) { translateFrom = ""; } else { translateFrom = TranslationServices.Core.TranslationServiceFacade.LanguageNameToLanguageCode(translateFrom); } if (documentTranslation.TranslateModeList.IndexOf(documentTranslation.SelectedTranslateMode) == 1) { contentType = TranslationServices.Core.TranslationServiceFacade.ContentType.HTML; } Task <string> task = TranslationServices.Core.TranslationServiceFacade.TranslateStringAsync( InputBox.Text, translateFrom, TranslationServices.Core.TranslationServiceFacade.LanguageNameToLanguageCode(documentTranslation.SelectedTargetLanguage), TranslationServices.Core.TranslationServiceFacade.CategoryID, contentType ); try { ResultBox.Text = await task; } catch (Exception ex) { ResultBox.Text = ex.Message; } }
public async Task <SortedDictionary <string, string> > TranslateToAllLanguages(string text, string from, string category, TranslationServices.Core.TranslationServiceFacade.ContentType contentType) { SortedDictionary <string, string> translatedDictionary = new SortedDictionary <string, string>(); foreach (KeyValuePair <string, string> language in TranslationServices.Core.TranslationServiceFacade.AvailableLanguages) { string translation = await TranslationServices.Core.TranslationServiceFacade.TranslateStringAsync(text, from, language.Key, category, contentType); translatedDictionary.Add(language.Key, translation); } ; return(translatedDictionary); }
public async Task <string> TranslateToAllLanguagesString(string text, string from, string category, TranslationServices.Core.TranslationServiceFacade.ContentType contentType) { StringWriter stringWriter = new StringWriter(); SortedDictionary <string, string> translatedDictionary = new SortedDictionary <string, string>(); translatedDictionary = await TranslateToAllLanguages(text, from, category, contentType); foreach (string key in translatedDictionary.Keys) { string value = string.Empty; try { translatedDictionary.TryGetValue(key, out value); } catch { }; stringWriter.WriteLine(key + ":\t" + value); } return(stringWriter.ToString()); }