Exemplo n.º 1
0
        private async void btnCreateInvoice_Click(object sender, RoutedEventArgs e)
        {
            if (btnCreateInvoice.IsEnabled == false)
            {
                MessageBox.Show("no xml file loaded");
                return;
            }

            btnSaveXSLT.IsEnabled = false;
            btnSave_XML.IsEnabled = false;

            string OriginalxmlFile = File.ReadAllText(openFileDialog.FileName);

            if (ToLanguageComboBox.Text == "English")
            {
                MessageBox.Show("Please select another language", "Translation not supported", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            ToTranslate toTranslate = new ToTranslate();

            toTranslate.TextToTranslate = OriginalxmlFile;
            toTranslate.ToLanguage      = ToLanguageComboBox.Text;
            //string HTMLstring = await new LanguageClass(blobConnectionString, containerName).ConvertXml2Html(OriginalxmlFile, ToLanguageComboBox.Text);
            string uri        = baseUri;
            string route      = "/api/convertxml2html";
            string HTMLstring = await new WebAPIHandler(httpClient).PostWebAPIToTranslate <ToTranslate>(uri, route, toTranslate);

            File.WriteAllText("eInvoice.html", HTMLstring);
            System.Diagnostics.Process.Start("eInvoice.html");

            btnSaveXSLT.IsEnabled = true;
            btnSave_XML.IsEnabled = true;
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        private async void cmbWord_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string      uri         = baseUri;
            string      route       = "/api/gettranslation";
            ToTranslate toTranslate = new ToTranslate();

            toTranslate.ToLanguage      = (string)cmbLanguage.SelectedItem;
            toTranslate.TextToTranslate = (string)cmbWord.SelectedItem;
            TxtTranslation.Text         = await new WebAPIHandler(httpClient).PostWebAPIToTranslate <ToTranslate>(uri, route, toTranslate);

            //txtTranslation.Text = new LanguageClass(blobConnectionString, containerName).GetTranslation((string)cmbWord.SelectedItem, (string)cmbLanguage.SelectedItem);
            if (String.IsNullOrEmpty(TxtTranslation.Text))
            {
                btnSave.IsEnabled = false;
            }
            else
            {
                btnSave.IsEnabled = true;
            }
        }