Example #1
0
            public TranslationResult TranslateText(string source, string sourceLanguage, string targetLanguage)
            {
                if (!IsValidLanguageCode(targetLanguage))
                {
                    throw new Exception("Invalid Target Language Code.");
                }
                else if (!IsValidLanguageCode(sourceLanguage))
                {
                    throw new Exception("Invalid Source Language Code.");
                }

                var response = TranslateMessageAsync(source, targetLanguage, source).Result;

                if (response.translatedMessage == null)
                {
                    return(null);
                }

                var result = new TranslationResult();

                result.DestinationLanguage = targetLanguage;
                result.SourceLanguage      = sourceLanguage;
                result.SourceText          = source;
                result.TranslatedText      = TranslateService.FixTranslatedString(response.translatedMessage);

                return(result);
            }