private async void TranslateButton_Click(object sender, RoutedEventArgs e) { string fromLanguage = FromLanguageComboBox.Text; LanguageClass languageClass = new LanguageClass(blobConnectionString, containerName); if (fromLanguage == "Detect") { string fromLanguageCode = languageClass.DetectLanguage(TextToTranslate.Text); fromLanguage = languageClass.GetLanguageFromCode(fromLanguageCode); if (fromLanguage.Contains("Unable to confidently detect input language.")) { MessageBox.Show("The source language could not be detected automatically " + "or is not supported for translation.", "Language detection failed", MessageBoxButton.OK, MessageBoxImage.Error); return; } } var toLanguageCode = languageClass.GetLanguageCode(ToLanguageComboBox.SelectedValue.ToString()); var textToTranslate = TextToTranslate.Text.Trim(); // var translation = await languageClass.translate(textToTranslate, ToLanguageComboBox.Text, fromLanguage); string uri = baseUri; string route = "api/translate"; ToTranslate toTranslate = new ToTranslate(); toTranslate.ToLanguage = ToLanguageComboBox.Text; toTranslate.TextToTranslate = textToTranslate; toTranslate.FromLanguage = fromLanguage; var translation = await new WebAPIHandler(httpClient).PostWebAPI2TranslateText <ToTranslate>(uri, route, toTranslate); TranslatedTextLabel.Text = translation; }
private void PopulateLanguageCombos() { // Add option to automatically detect the source language FromLanguageComboBox.Items.Add("Detect"); List <string> list = new LanguageClass(blobConnectionString, containerName).FillLanguages(); foreach (var item in list) { FromLanguageComboBox.Items.Add(item); } ToLanguageComboBox.ItemsSource = list; // Set default languages FromLanguageComboBox.SelectedItem = "Detect"; ToLanguageComboBox.SelectedItem = "English"; }
public PageSettings() { InitializeComponent(); // Get languages for drop-downs List <string> list = new LanguageClass(blobConnectionString, containerName).GetTranslatedXsltLanguages(); cmbLanguage.ItemsSource = list; List <string> originalList = new LanguageClass(blobConnectionString, containerName).GetWords(); foreach (var word in originalList) { if (word != "") { cmbWord.Items.Add(word); } } ; }
private async Task <string> GetXmlTranslated4Names(string xmlFile, string ToLanguage, string FromLanguage) { string toLanguageCode = new LanguageClass().GetLanguageCode(ToLanguage); string nameStartSearchTxt = "<cbc:Name>", nameEndSearchTxt = "</cbc:Name>"; int nameStartPtr = 0, nameEndPtr = 0; string NameOriginalText, NameTranslatedText; int lineItemStart = xmlFile.IndexOf("<cac:Item>"); nameStartPtr = xmlFile.IndexOf(nameStartSearchTxt, lineItemStart); while (nameStartPtr != -1) { if (nameStartPtr != -1) { nameEndPtr = xmlFile.IndexOf(nameEndSearchTxt, nameStartPtr); if (nameEndPtr != -1) { NameOriginalText = xmlFile.Substring(nameStartPtr + nameStartSearchTxt.Length, nameEndPtr - nameStartPtr - nameStartSearchTxt.Length); NameTranslatedText = await new LanguageClass().translate(NameOriginalText, ToLanguage, FromLanguage); xmlFile = xmlFile.Replace(nameStartSearchTxt + NameOriginalText + nameEndSearchTxt, nameStartSearchTxt + NameTranslatedText + nameEndSearchTxt); } } else { } nameStartPtr = xmlFile.IndexOf(nameStartSearchTxt, nameEndPtr); } return(xmlFile); }