public TranslationResult GetTranslationFromGoogleAppScript(string text, string sourceLang, string destinationLang, string baseurl)
        {
            string baseUrl = baseurl;

            baseUrl += "?text=" + System.Web.HttpUtility.UrlEncode(text);
            baseUrl += "&source=" + sourceLang;
            baseUrl += "&target=" + destinationLang;

            string            response = Utils.GetHttpResponse(baseUrl);
            TranslationResult res      = new TranslationResult();

            res.Sentences = new List <string>()
            {
                response
            };
            return(res);
        }
        public TranslationResult GetTranslation(string text, string sourceLang, string destinationLang, string apikey)
        {
            string baseUrl = "https://translation.googleapis.com/language/translate/v2";

            /* {
             *                          "sentences":[{"trans":"текст","orig":"text","translit":"tekst","src_translit":""}],
             *                          "dict":
             *                          [
             *                                          {"pos":"существительное","terms":["текст","текстовый файл","оригинал","руководство","тема","подлинный текст","цитата из библии"]},
             *                                          {"pos":"глагол","terms":["пис `ать крупным почерком"]}
             *                          ],
             *                          "src":"en",
             *                          "server_time":12
             *                  }
             * */

            baseUrl += "?key=" + apikey;

            string data = Utils.CreateQuerystring(new Dictionary <string, string>()
            {
                //{"client","gtx"},
                //{"otf", "1"},
                //{"pc", "0"},
                { "source", sourceLang },
                { "target", destinationLang },
                //{"hl", destinationLang},
                { "q", text },
                //{"dt", "t" },
            });

            string            response = Utils.GetHttpResponse(baseUrl, data);
            Response          resp     = Newtonsoft.Json.JsonConvert.DeserializeObject <Response>(response);
            TranslationResult res      = new TranslationResult();

            res.Sentences = new List <string>()
            {
                resp.data.translations[0].translatedText
            };
            return(res);
        }
        private TranslationResult ParseResponse(JObject json)
        {
            TranslationResult res = new TranslationResult();

            JToken        sentences     = json["sentences"];
            List <string> sentenceTexts = new List <string>();

            foreach (JToken sent in sentences.Children())
            {
                sentenceTexts.Add(sent.Value <string>("trans"));
            }
            string fullText = string.Join(" ", sentenceTexts);

            if (!string.IsNullOrWhiteSpace(fullText))
            {
                res.Sentences.Add(fullText);
            }

            JToken dictionary = json["dict"];

            if (dictionary != null)
            {
                foreach (JToken dToken in dictionary.Children())
                {
                    DictionaryItem d = new DictionaryItem();
                    d.Title = dToken.Value <string>("pos");
                    JToken terms = dToken["terms"];
                    foreach (JToken term in terms.Children())
                    {
                        d.Terms.Add(term.Value <string>());
                    }
                    res.DictionaryItems.Add(d);
                }
            }

            res.SourceLanguage = json.Value <string>("src");
            return(res);
        }
        private TranslationResult ParseResponse(JArray json)
        {
            TranslationResult res           = new TranslationResult();
            List <string>     sentenceTexts = new List <string>();

            foreach (var cjson in json)
            {
                foreach (var ccjson in cjson)
                {
                    sentenceTexts.Add(ccjson[0].Value <string>());
                }
            }

            string fullText = string.Join("", sentenceTexts);

            if (!string.IsNullOrWhiteSpace(fullText))
            {
                res.Sentences.Add(fullText);
            }

            res.SourceLanguage = "en";
            return(res);
        }