Esempio n. 1
0
        public string Translate(string text, DetectedLanguage from, Language to)
        {
            TranslatorContainer tc   = InitializeTranslatorContainer();
            var    translationResult = TranslateString(tc, text, from, to);
            string s = translationResult.Text;

            return(s);
        }
Esempio n. 2
0
        private static Translation TranslateString(TranslatorContainer tc, string inputString, DetectedLanguage sourceLanguage, Language targetLanguage)
        {
            // Generate the query
            var translationQuery = tc.Translate(inputString, targetLanguage.Code, sourceLanguage.Code);

            // Call the query and get the results as a List
            var translationResults = translationQuery.Execute().ToList();

            // Verify there was a result
            if (translationResults.Count() <= 0)
            {
                return(null);
            }

            // In case there were multiple results, pick the first one
            var translationResult = translationResults.First();

            return(translationResult);
        }