Example #1
0
 private void SourceInput_KeyUp(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter)
     {
         TranslateInput.Focus();
     }
 }
Example #2
0
 private void ModeButton_Click(object sender, RoutedEventArgs e)
 {
     _tester.FullTest = !_tester.FullTest;
     UpdateModeText();
     UpdateStatus(_tester.Left);
     TranslateInput.Focus();
 }
Example #3
0
        public string Trans(string word)
        {
            List <string>  _results = new List <string>();
            TranslateInput input    = new TranslateInput();

            string[] srcText = new string[] { word };
            SetLanguage(word);
            input.TargetLanguage = TargetLangCode;
            input.SourceText     = SourceLangCode;

            try
            {
                var response = TranService.Translations.List(srcText, input.TargetLanguage).Execute();
                foreach (TranslationsResource translation in response.Translations)
                {
                    if (translation.DetectedSourceLanguage == SourceLangCode)
                    {
                        _results.Add(translation.TranslatedText);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            if (_results.Count > 0)
            {
                return(_results.ElementAtOrDefault(0));
            }
            else
            {
                return(string.Empty);
            }
        }
Example #4
0
    public List <string> Trans(string[] words)
    {
        List <string>  _results = new List <string>();
        TranslateInput input    = new TranslateInput();

        input.TargetLanguage = "vi";
        var service = new TranslateService(new BaseClientService.Initializer()
        {
            ApiKey          = "AIzaSyA5naCjbPLqFdhaY6-f24bwoTwKSTHS9m4",
            ApplicationName = "CafeT"
        });

        string[] srcText = words.Distinct().ToArray();
        srcText = srcText.Take(100).ToArray();
        try
        {
            var response = service.Translations.List(srcText, input.TargetLanguage).Execute();
            foreach (TranslationsResource translation in response.Translations)
            {
                _results.Add(translation.TranslatedText);
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        return(_results);
    }
Example #5
0
        private void Next()
        {
            var left = _tester.Left;
            var next = _tester.Next();

            if (_tester.FullTest && left == 1)
            {
                UpdateStatus(0);
                MessageBox.Show("Test Completed!");
            }

            TranslateInput.Background = new SolidColorBrush(Colors.White);

            SourceButton.Content   = next;
            SourceButton.IsChecked = false;

            UpdateStatus(_tester.Left);

            TranslateInput.Text = string.Empty;
            TranslateInput.Focus();
        }
Example #6
0
        static void Main(string[] args)
        {
            // Initialize this sample.
            CommandLine.EnableExceptionHandling();
            CommandLine.DisplayGoogleSampleHeader("Translate Sample");

            // Ask for the user input.
            TranslateInput input = CommandLine.CreateClassFromUserinput <TranslateInput>();

            // Create the service.
            var service = new TranslateService {
                Key = GetApiKey()
            };

            // Execute the first translation request.
            CommandLine.WriteAction("Translating to '" + input.TargetLanguage + "' ...");

            string[] srcText = new[] { "Hello world!", input.SourceText };
            TranslationsListResponse response = service.Translations.List(srcText, input.TargetLanguage).Fetch();
            var translations = new List <string>();

            foreach (TranslationsResource translation in response.Translations)
            {
                translations.Add(translation.TranslatedText);
                CommandLine.WriteResult("translation", translation.TranslatedText);
            }

            // Translate the text (back) to english.
            CommandLine.WriteAction("Translating to english ...");

            response = service.Translations.List(translations, "en").Fetch();

            foreach (TranslationsResource translation in response.Translations)
            {
                CommandLine.WriteResult("translation", translation.TranslatedText);
            }

            // ...and we are done.
            CommandLine.PressAnyKeyToExit();
        }
        private async Task Run()
        {
            var key = GetApiKey();

            // Ask for the user input.
            TranslateInput input = CreateClassFromUserinput <TranslateInput>();

            // Create the service.
            var service = new TranslateService(new BaseClientService.Initializer()
            {
                ApiKey          = key,
                ApplicationName = "Translate API Sample"
            });

            // Execute the first translation request.
            Console.WriteLine("Translating to '" + input.TargetLanguage + "' ...");

            string[] srcText  = new[] { "Hello world!", input.SourceText };
            var      response = await service.Translations.List(srcText, input.TargetLanguage).ExecuteAsync();

            var translations = new List <string>();

            foreach (TranslationsResource translation in response.Translations)
            {
                translations.Add(translation.TranslatedText);
                Console.WriteLine("translation :" + translation.TranslatedText);
            }

            // Translate the text (back) to English.
            Console.WriteLine("Translating to English ...");

            response = service.Translations.List(translations, "en").Execute();
            foreach (TranslationsResource translation in response.Translations)
            {
                Console.WriteLine("translation :" + translation.TranslatedText);
            }
        }
Example #8
0
        public List <string> Trans(string[] words)
        {
            List <string>  _results = new List <string>();
            TranslateInput input    = new TranslateInput();

            input.TargetLanguage = TargetLangCode;
            input.SourceText     = SourceLangCode;

            string[] srcText = words.Distinct().ToArray();
            srcText = srcText.TakeMax(100).ToArray();
            try
            {
                var response = TranService.Translations.List(srcText, input.TargetLanguage).Execute();
                foreach (TranslationsResource translation in response.Translations)
                {
                    _results.Add(translation.TranslatedText);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(_results);
        }
        public Task <TranslateOutput> Translate(TranslateInput input)
        {
            var output = BaiduAiHelper.PostTranslate(input);

            return(Task.FromResult(output));
        }