private void OnSwapLanguageButtonClicked(object sender, RoutedEventArgs e)
        {
            if (InputLanguage != null && OutputLanguage != null)
            {
                this.inputText.Text         = this.outputText.Text;
                this.previousTranslatedText = this.inputText.Text;
                this.outputText.Text        = string.Empty;

                customOutputLanguage = InputLanguage;
                InputLanguage        = InputLanguageCollection.FirstOrDefault(l => l.Code.Equals(OutputLanguage.Code, StringComparison.OrdinalIgnoreCase));
            }
        }
        private async Task DetectedLanguageAsync(string text)
        {
            try
            {
                if (!string.IsNullOrEmpty(text))
                {
                    DetectedLanguageResult detectedLanguageResult = await this.translatorTextService.DetectLanguageAsync(text);

                    if (detectedLanguageResult != null)
                    {
                        InputLanguage = InputLanguageCollection.FirstOrDefault(l => l.Code.Equals(detectedLanguageResult.Language, StringComparison.OrdinalIgnoreCase));
                    }
                }
            }
            catch
            {
                // just ignore the exception here and let user select the language
            }
        }
コード例 #3
0
        private void OnSwapLanguageButtonClicked(object sender, RoutedEventArgs e)
        {
            var inputLanguage  = this.inputLanguageComboBox.SelectedValue as LanguageDictionary;
            var outputLanguage = this.outputLanguageComboBox.SelectedValue as Language;

            if (inputLanguage == null || outputLanguage == null)
            {
                return;
            }

            this.inputText.Text         = this.outputText.Text;
            this.previousTranslatedText = this.inputText.Text;
            this.outputText.Text        = string.Empty;
            LanguageDictionary newInputLanguage = InputLanguageCollection.FirstOrDefault(l => l.Code.Equals(outputLanguage.Code, StringComparison.OrdinalIgnoreCase));

            if (newInputLanguage != null)
            {
                Language newOutputLanguage = newInputLanguage.Translations?.FirstOrDefault(l => l.Code.Equals(inputLanguage.Code, StringComparison.OrdinalIgnoreCase));
                this.outputLanguageName = newOutputLanguage?.Name ?? this.outputLanguageName;
                this.inputLanguageComboBox.SelectedValue = newInputLanguage;
            }
        }
コード例 #4
0
        private async Task DetectedLanguageAsync(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            try
            {
                DetectedLanguageResult detectedLanguageResult = await this.translatorTextService?.DetectLanguageAsync(text);

                if (detectedLanguageResult != null)
                {
                    this.inputLanguage = InputLanguageCollection
                                         .FirstOrDefault(l => l.Code.Equals(detectedLanguageResult.Language, StringComparison.OrdinalIgnoreCase));
                    if (this.inputLanguage != null)
                    {
                        switch (this.pivotControl.SelectedIndex)
                        {
                        case 0:     // Pivot Text
                            this.inputLanguageComboBox.SelectedValue = this.inputLanguage;
                            break;

                        case 1:     // Pivot Image
                            this.detectedLanguageTextBox.Text = $"Detected Language: {this.inputLanguage.Name}";
                            UpdateOutputLanguageCombobox(this.inputLanguage);
                            break;
                        }
                    }
                }
            }
            catch
            {
                // just ignore the exception here and let user select the language
            }
        }