forked from BenDizer/SMM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClass1.cs
More file actions
50 lines (42 loc) · 1.31 KB
/
Class1.cs
File metadata and controls
50 lines (42 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using Newtonsoft.Json;
using System.IO;
using System.Net;
namespace Translator
{
class YandexTranslator
{
public string Translate(string s, string lang, string key)
{
if (s.Length > 0)
{
WebRequest request = WebRequest.Create("https://translate.yandex.net/api/v1.5/tr.json/translate?"
+ "key=" + key
+ "&text=" + s
+ "&lang=" + lang);
WebResponse response = request.GetResponse();
using (StreamReader stream = new StreamReader(response.GetResponseStream()))
{
string line;
if ((line = stream.ReadLine()) != null)
{
Translation translation = JsonConvert.DeserializeObject<Translation>(line);
s = "";
foreach (string str in translation.text)
{
s += str;
}
}
}
return s;
}
else
return "";
}
}
class Translation
{
public string code { get; set; }
public string lang { get; set; }
public string[] text { get; set; }
}
}