PDA

View Full Version : مترجم گوگل



alnajon
چهارشنبه 27 خرداد 1394, 13:49 عصر
با سلام
دوستان سورس مترجم گوگل رو دارید ؟؟

یکی قبلا خودم داشتم به خوبی کار میکرد اما الان فکر کنم با تغییرات گوگل از کار افتاده

یکی هم اینجا هست :
http://barnamenevis.org/showthread.php?320183-%D8%AF%D8%A7%D9%86%D9%84%D9%88%D8%AF-%D8%B3%D9%88%D8%B1%D8%B3-%D9%86%D9%85%D9%88%D9%86%D9%87-%DA%A9%D8%AF-%D9%85%D8%AA%D8%B1%D8%AC%D9%85-%DA%AF%D9%88%DA%AF%D9%84-%D8%B1%D8%A7%DB%8C%DA%AF%D8%A7%D9%86-!-Google-Api-Free

که برای VB نوشته شده و کار میکنه اما نتونستم به C# تبدیل کنم

ممنون میشم کمک کنید

Twoplus2010
پنج شنبه 28 خرداد 1394, 10:53 صبح
سلام خدمت شما
public partial class GoogleTranslate
{
/// <summary>
/// ترجمه کلمه و مت.ن
/// </summary>
/// <param name="input">کلمه یا متن</param>
/// <param name="langFrom">از</param>
/// <param name="langTo">به</param>
/// <returns></returns>
public static string TranslateText(string input, string langFrom, string langTo)
{
WebClient webClient = new WebClient();
webClient.Headers.Add("Charset", "text/html; charset=UTF-8");
string address = "http://www.google.com/translate_t?hl=da&ie=UTF8&text=" + input + "&langpair=" + langFrom + "|" + langTo;
string str1 = webClient.DownloadString(address);
string str2 = str1.Substring(checked(str1.IndexOf("<span id=result_box") + 19));
string input1 = str2.Remove(checked(str2.IndexOf("</span></span>") + 7));
int count = new Regex("<span").Matches(input1).Count;
string Result = "";
int num1 = 0;
int num2 = checked(count - 1);
int num3 = num1;
while (num3 <= num2)
{
string str4 = input1.Substring(checked(input1.IndexOf("<span") + 5));
string str5 = str4.Remove(str4.IndexOf("</span>"));
string str6 = str5.Substring(checked(str5.IndexOf(">") + 1));
input1 = input1.Substring(checked(input1.IndexOf("</span>") + 7));
Result += str6;
checked { ++num3; }
}
return Result;
}
}