コード例 #1
0
        public async Task <JsonResult> Index(LanguageMaster languageMaster)
        {
            var result = string.Empty;

            if (languageMaster.LanguageCode != "NA")
            {
                try
                {
                    // Language code for selected language in the dropdown list.
                    string code = languageMaster.LanguageCode;
                    // NOTE: Replace this example key with a valid subscription key.
                    string key = "<Subscription Key>";
                    //host url
                    string host = "https://api.cognitive.microsofttranslator.com";
                    string path = "/translate?api-version=3.0";
                    // Translate to dropdown selected language.
                    string params_ = $"&to={code}";

                    string uri = host + path + params_;

                    string text = languageMaster.Text;
                    result = await obj.Translate(uri, text, key);
                }
                catch (Exception ex)
                {
                    _logger.LogError($" Translate text failure : {ex.Message} ");
                }
            }

            return(Json(result));
        }
コード例 #2
0
        public async void Execute(object parameter)
        {
            string text = _inputOutputText[0];

            // launch translate text service
            TranslateTextService translateTextService = new TranslateTextService(text);

            // set text and translated text
            _inputOutputText[1] = await translateTextService.Translate();

            // launch callback function
            var callback = parameter as Action;

            callback();
        }