Перевод текста с помощью Google.

public static string Translate(string text,string l)
{
    //l = the language you want....e.g. "es" for spanish, "ja" = japanese, "fr" for french
    string translated = null;
    HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create("http://translate.google.com/translate_s?hl=en&clss=&q=" + text.Replace(" ", "+") + "&tq=&sl=en&tl=" + l);
    HttpWebResponse res = (HttpWebResponse)hwr.GetResponse();
    StreamReader sr = new StreamReader(res.GetResponseStream());
    string html = sr.ReadToEnd();
    int start = 0;
    int end = 0;
    Regex r = new Regex("");
    Match first = null;
    foreach (Match m in r.Matches(html))
    {
        if (m.Value == "")
        {
            first = m;
            break;
        }
    }
    start = first.Index + first.Length;
    r = new Regex("");
    Match Second = null;
    foreach (Match m in r.Matches(html)) 
    {
        if (m.Value == "")
        {
            Second = m;
            break;
        }
    }
    end = Second.Index - start;
    translated = html.Substring(start, end);
    return translated;
}
Взято с http://www.dreamincode.net

Комментариев нет:

Отправить комментарий

Большая просьба, не писать в комментариях всякую ерунду не по теме!