Esempio n. 1
0
        private void BtnTrans_Click(object sender, EventArgs e)
        {
            var client = new AmazonTranslateClient();

            var request = new TranslateTextRequest
            {
                Text = txtEn.Text,
                SourceLanguageCode = "en",
                TargetLanguageCode = "vi"
            };
            var result = client.TranslateText(request);

            txtVi.Text = result.TranslatedText;
        }
Esempio n. 2
0
        private void TranslateButton_Click(object sender, RoutedEventArgs e)
        {
            var accessKey = "AKIAUBMTEBYUP272NQGE";
            var secretKey = "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";

            var client  = new AmazonTranslateClient();
            var request = new TranslateTextRequest
            {
                Text = MyTextBox.Text,
                SourceLanguageCode = "en",
                TargetLanguageCode = "vi",
            };
            var respone = client.TranslateText(request);

            MyLable.Content = respone.TranslatedText;
        }
Esempio n. 3
0
        private void btn_translate_Click(object sender, EventArgs e)
        {
            var accessKey = "AKIASASJUZ22KX7S2CPS";
            var secretKey = "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";

            var client = new AmazonTranslateClient(accessKey, secretKey, RegionEndpoint.APSoutheast1);

            var request = new TranslateTextRequest
            {
                Text = txt_langSource.Text,
                SourceLanguageCode = "en",
                TargetLanguageCode = "vi"
            };
            var result = client.TranslateText(request);

            txt_langTarget.Text = result.TranslatedText;
        }
Esempio n. 4
0
        /// <summary>
        /// translates the text input
        /// </summary>
        /// <param name="sourceLang"></param>
        /// <param name="targetLang"></param>
        /// <param name="textToTranslate"></param>
        /// <param name="categoryId"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        internal string Translate(string sourceLang, string targetLang, string textToTranslate)
        {
            //convert our language codes
            var sourceLc = convertLangCode(sourceLang);
            var targetLc = convertLangCode(targetLang);


            var translatedText = string.Empty;


            Amazon.Runtime.AWSCredentials awsCreds  = null;
            Amazon.RegionEndpoint         awsRegion = null;


            if (_options.SelectedAuthType == MtTranslationOptions.AWSAuthType.Profile)
            {
                var credentialsFile = new SharedCredentialsFile();                                                        //TODO: always SharedCredentialsFile?
                var prof            = credentialsFile.TryGetProfile(_options.ProfileName, out CredentialProfile profile); //TODO: add in error-handling
                awsCreds  = profile.GetAWSCredentials(credentialsFile);
                awsRegion = profile.Region;
            }
            else
            {
                awsCreds  = new Amazon.Runtime.BasicAWSCredentials(_accessKey, _secretKey);
                awsRegion = Amazon.RegionEndpoint.GetBySystemName(_options.RegionName);
            }

            var tclient  = new AmazonTranslateClient(awsCreds, awsRegion);
            var trequest = new TranslateTextRequest();

            trequest.SourceLanguageCode = sourceLc;
            trequest.TargetLanguageCode = targetLc;
            trequest.Text = textToTranslate;
            try
            {
                var result = tclient.TranslateText(trequest);
                System.Diagnostics.Debug.WriteLine(result.TranslatedText);
                translatedText = result.TranslatedText;
            }
            catch (Amazon.Translate.AmazonTranslateException e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
                throw e;
            }
            return(translatedText);
        }
        public ActionResult TranslateComment(TranslateCommentViewModel comment)
        {
            var translate = new AmazonTranslateClient("AWS-ACCESS-KEY", "AWS-SECRET-KEY", RegionEndpoint.USEast1);
            var request   = new TranslateTextRequest()
            {
                Text = comment.CommentText, SourceLanguageCode = "en", TargetLanguageCode = comment.TargetLanguage
            };
            var model = new TranslatedCommentViewModel()
            {
                CommentText       = comment.CommentText,
                SubmitterName     = comment.SubmitterName,
                TargetLangauge    = comment.TargetLanguage,
                TranslateResponse = translate.TranslateText(request) // Make the actual call to Amazon Translate
            };

            return(View(model));
        }
Esempio n. 6
0
        private void OnTranslate(object sender, RoutedEventArgs e)
        {
            string translateText = txtTextInput.Text.Trim();

            if (translateText != "")
            {
                var translate = new AmazonTranslateClient();
                var request   = new TranslateTextRequest()
                {
                    Text = translateText,
                    SourceLanguageCode = "en",
                    TargetLanguageCode = "vi"
                };
                TranslateTextResponse translateResponse = translate.TranslateText(request);
                txtTextResult.Text = translateResponse.TranslatedText;
            }
        }
Esempio n. 7
0
        private void txtEnglish_TextChanged(object sender, TextChangedEventArgs e)
        {
            var accessKey = "AKIASHKYRPNVFN5WYH4X";
            var secretKey = "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";

            var client = new AmazonTranslateClient(accessKey, secretKey, RegionEndpoint.APSoutheast1);

            var request = new TranslateTextRequest
            {
                Text = txtEnglish.Text,
                SourceLanguageCode = "en",
                TargetLanguageCode = "vi"
            };
            var result = client.TranslateText(request);

            txtVietnamese.Text = result.TranslatedText;
        }
Esempio n. 8
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var sourceText = txtSoure.Text;

            var client  = new AmazonTranslateClient();
            var request = new TranslateTextRequest()
            {
                Text = sourceText,
                SourceLanguageCode = "en",
                TargetLanguageCode = "vi"
            };

            try
            {
                var response = client.TranslateText(request);
                txtInfo.Text = string.Empty;
                txtInfo.Text = response.TranslatedText;
            }
            catch (Exception)
            {
            }
        }
Esempio n. 9
0
        private static void translateText(string userSentence, AmazonTranslateClient client)
        {
            // Danish
            // Italian
            // French
            // Spanish
            string[] languageCodes          = { "da", "it", "fr", "es" };
            string[] languages              = { "DANISH", "ITALIAN", "FRENCH", "SPANISH" };
            TranslateTextRequest[] requests = new TranslateTextRequest[4];

            // Create a list of request objects
            for (int i = 0; i < 4; i++)
            {
                TranslateTextRequest request = new TranslateTextRequest
                {
                    SourceLanguageCode = "en",
                    TargetLanguageCode = languageCodes[i],
                    Text = userSentence
                };

                requests[i] = request;
            }
            try
            {
                int i = 0;
                foreach (var r in requests)
                {
                    TranslateTextResponse response = client.TranslateText(r);
                    Console.WriteLine(languages[i] + ":  " + response.TranslatedText);
                    i++;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }