-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPuvox__google_translate.cs
126 lines (102 loc) · 2.82 KB
/
Puvox__google_translate.cs
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using System.Drawing;
using System.Xml.Linq;
using System.Reflection;
using System.Diagnostics;
using System.Net;
using System.Globalization;
using System.Text.RegularExpressions;
using System.IO;
using Microsoft.Win32;
using System.Collections.Specialized;
using System.Threading.Tasks;
using System.Security.Cryptography;
using Google.Cloud.Translation.V2;
namespace PuvoxLibrary
{
public partial class GoogleTranslate_
{
private void m(dynamic x) { System.Windows.Forms.MessageBox.Show(x); }
TranslationClient gTranslateClient;
public GoogleTranslate_(string gsApiKey)
{
try
{
gTranslateClient = TranslationClient.Create();
}
catch(Exception e)
{
m(e);
}
}
public string GTranslate(string text, string targetLanguageCode, string sourceLanguageCode)
{
var response = gTranslateClient.TranslateText(text, targetLanguageCode, sourceLanguageCode);
return response.TranslatedText;
}
/*
public string selectedLang = "en";
public Dictionary<string, Dictionary<string, string>> transl_texts;
public string translate(string txt)
{
if (transl_texts.ContainsKey(txt) && transl_texts[txt].ContainsKey(selectedLang))
{
return transl_texts[txt][selectedLang];
}
return translatedReady(selectedLang, txt);
}
public string translatedReady(string targetLang, string englishValue)
{
string text = englishValue;
string key = "translReady_" + md5(englishValue) + "_" + targetLang;
if (targetLang != "en")
{
string registryValue = getRegistryValue(key);
if (registryValue == null)
{
text = GTranslate_checker(englishValue, targetLang);
setRegistryValue(key, text);
}
else
{
text = registryValue;
}
}
else
{
setRegistryValue(key, englishValue);
}
return text;
}
public string getTranslateCode(string desiredLang)
{
if (!desiredLang)
{
return false;
}
desiredLang = desiredLang.toLowerCase();
if (langs[desiredLang])
{
return desiredLang;
}
var keys = Object.keys(langs).filter(function(key) {
if (typeof langs[key] !== 'string')
{
return false;
}
return langs[key].toLowerCase() === desiredLang;
});
return keys[0] || false;
}
public bool istranslateLangSupported(desiredLang)
{
return Boolean(getCode(desiredLang));
}
*/
}
}