public static GWords Translate(GLanguages inlang, GLanguages outlang, string trtext)
 {
     string url = "http://www.google.com/translate_a/t?client=t&sl=" + inlang.ToString() + "&tl=" + outlang.ToString();
     StreamReader streamreader = null;
     try
     {
         byte[] bytearr = Encoding.UTF8.GetBytes("text=" +trtext);
         HttpWebRequest trHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
         trHttpWebRequest.UserAgent = "Mozilla/5.0";
         trHttpWebRequest.Method = "POST";
         trHttpWebRequest.ContentLength = bytearr.Length;
         trHttpWebRequest.Headers.Add("Accept-Encoding", "deflate");
         trHttpWebRequest.AllowAutoRedirect = false;
         trHttpWebRequest.GetRequestStream().Write(bytearr, 0, bytearr.Length);
         HttpWebResponse  trHttpWebResponse = (HttpWebResponse)trHttpWebRequest.GetResponse();
         streamreader = new StreamReader(trHttpWebResponse.GetResponseStream(), Encoding.UTF8);
     }
     catch (Exception ex)
     {
         Console.WriteLine("Erorr: can't connect www.google.com");
         Console.WriteLine("Description:");
         Console.WriteLine(ex.Message);
         return null;
     }
     return new GWords(streamreader.ReadToEnd());
 }
Example #2
0
        public static GWords Translate(string inlang, string outlang, string trtext)
        {
            GLanguages lang1 = StringToGLanguages(inlang);
            GLanguages lang2 = StringToGLanguages(outlang);

            Console.WriteLine(lang2.ToString());
            return(Translate(lang1, lang2, trtext));
        }
Example #3
0
        public static GWords Translate(GLanguages inlang, GLanguages outlang, string trtext)
        {
            string       url          = "http://www.google.com/translate_a/t?client=t&sl=" + inlang.ToString() + "&tl=" + outlang.ToString();
            StreamReader streamreader = null;

            try
            {
                byte[]         bytearr          = Encoding.UTF8.GetBytes("text=" + trtext);
                HttpWebRequest trHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                trHttpWebRequest.UserAgent     = "Mozilla/5.0";
                trHttpWebRequest.Method        = "POST";
                trHttpWebRequest.ContentLength = bytearr.Length;
                trHttpWebRequest.Headers.Add("Accept-Encoding", "deflate");
                trHttpWebRequest.AllowAutoRedirect = false;
                trHttpWebRequest.GetRequestStream().Write(bytearr, 0, bytearr.Length);
                HttpWebResponse trHttpWebResponse = (HttpWebResponse)trHttpWebRequest.GetResponse();
                streamreader = new StreamReader(trHttpWebResponse.GetResponseStream(), Encoding.UTF8);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Erorr: can't connect www.google.com");
                Console.WriteLine("Description:");
                Console.WriteLine(ex.Message);
                return(null);
            }
            return(new GWords(streamreader.ReadToEnd()));
        }