示例#1
0
 public Task <List <Translation> > GetTranslations(string translationApiKey,
                                                   string textToTranslate,
                                                   Language languageFrom,
                                                   List <Language> languagesTo)
 {
     return(_translationApi.Translate(translationApiKey, textToTranslate, languageFrom, languagesTo));
 }
示例#2
0
        protected async Task <string> TranslateText(string requestedText)
        {
            string translatedText = string.Empty;

            requestedText = requestedText.Replace("\n", " ").Replace("\f", " ");

            try
            {
                var translatedContent = await _translationApi.Translate(requestedText, _supportedTranslation.ToString().ToLower());

                if (translatedContent != null && translatedContent.success.total > 0)
                {
                    translatedText = translatedContent.contents.translated;
                }
            }
            catch (ApiException apiException)
            {
                _logger.LogError($"Error translating text into {_supportedTranslation}; details: {apiException.Message} @ {apiException.StackTrace}");
            }

            return(translatedText);
        }