private async void detectButton_Click(object sender, RoutedEventArgs e)
        {
            if (apiKey != null && !string.IsNullOrEmpty(text1.Text))
            {
                wrapper.ApiKey = apiKey;
                try
                {
                    string lang = await wrapper.DetectLanguage(text1.Text);

                    languagesCombo.SelectedValue = lang;
                }
                catch (YandexTranslateException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Exemplo n.º 2
0
        public async Task DetectLanguageJsonTest()
        {
            YandexTranslateSdk wrapper = new YandexTranslateSdk();

            wrapper.ApiKey = _apiKey;
            wrapper.IsJson = true;
            string result = await wrapper.DetectLanguage(_randomEnglishText);

            Assert.Equal(result, "en");
        }
Exemplo n.º 3
0
        public async Task DetectLanguageXmlTest()
        {
            YandexTranslateSdk wrapper = new YandexTranslateSdk();

            wrapper.ApiKey = _apiKey;
            wrapper.IsJson = false;
            string result = await wrapper.DetectLanguage("Привет");

            Assert.Equal(result, "ru");
        }
        public async Task <IActionResult> Translate(TranslateViewModel model)
        {
            if (ModelState.IsValid)
            {
                YandexTranslateSdk wrapper = new YandexTranslateSdk();
                wrapper.ApiKey = model.Key;
                string inputLanguage = await wrapper.DetectLanguage(model.InputText);

                string outputLanguage = model.OutputLanguage;
                string direction      = inputLanguage + "-" + outputLanguage;
                model.OutputText = await wrapper.TranslateText(model.InputText, direction);

                model.Languages = new List <string>(TempData["Languages"] as string[]);

                ModelState.Clear();

                return(View("Index", model));
            }
            return(View("Index", model));
        }
 public virtual async Task <string> DetectLanguageAsync(string text)
 {
     return(await _yandexTranslateSdk.DetectLanguage(text));
 }