-
Notifications
You must be signed in to change notification settings - Fork 4
/
Chat Translator
385 lines (342 loc) · 10.2 KB
/
Chat Translator
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
--[[
Message Translator
Made by Aim, updated by cli
Credits to Riptxde for the sending chathook
--]]
if not game['Loaded'] then game['Loaded']:Wait() end; repeat wait(.06) until game:GetService('Players').LocalPlayer ~= nil
local YourLang = "en" -- Language code that the messages are going to be translated to
local googlev = isfile'googlev.txt' and readfile'googlev.txt' or ''
function googleConsent(Body) -- Because google really said: "Fuck you."
local args = {}
for match in Body:gmatch('<input type="hidden" name=".-" value=".-">') do
local k,v = match:match('<input type="hidden" name="(.-)" value="(.-)">')
args[k] = v
end
googlev = args.v
writefile('googlev.txt', args.v)
end
local function got(url, Method, Body) -- Basic version of https://www.npmjs.com/package/got using synapse's request API for google websites
Method = Method or "GET"
local res = request({
Url = url,
Method = Method,
Headers = {cookie="CONSENT=YES+"..googlev},
Body = Body
})
if res.Body:match('https://consent.google.com/s') then
print('consent')
googleConsent(res.Body)
res = syn.request({
Url = url,
Method = "GET",
Headers = {cookie="CONSENT=YES+"..googlev}
})
end
return res
end
local languages = {
auto = "Automatic",
af = "Afrikaans",
sq = "Albanian",
am = "Amharic",
ar = "Arabic",
hy = "Armenian",
az = "Azerbaijani",
eu = "Basque",
be = "Belarusian",
bn = "Bengali",
bs = "Bosnian",
bg = "Bulgarian",
ca = "Catalan",
ceb = "Cebuano",
ny = "Chichewa",
['zh-cn'] = "Chinese Simplified",
['zh-tw'] = "Chinese Traditional",
co = "Corsican",
hr = "Croatian",
cs = "Czech",
da = "Danish",
nl = "Dutch",
en = "English",
eo = "Esperanto",
et = "Estonian",
tl = "Filipino",
fi = "Finnish",
fr = "French",
fy = "Frisian",
gl = "Galician",
ka = "Georgian",
de = "German",
el = "Greek",
gu = "Gujarati",
ht = "Haitian Creole",
ha = "Hausa",
haw = "Hawaiian",
iw = "Hebrew",
hi = "Hindi",
hmn = "Hmong",
hu = "Hungarian",
is = "Icelandic",
ig = "Igbo",
id = "Indonesian",
ga = "Irish",
it = "Italian",
ja = "Japanese",
jw = "Javanese",
kn = "Kannada",
kk = "Kazakh",
km = "Khmer",
ko = "Korean",
ku = "Kurdish (Kurmanji)",
ky = "Kyrgyz",
lo = "Lao",
la = "Latin",
lv = "Latvian",
lt = "Lithuanian",
lb = "Luxembourgish",
mk = "Macedonian",
mg = "Malagasy",
ms = "Malay",
ml = "Malayalam",
mt = "Maltese",
mi = "Maori",
mr = "Marathi",
mn = "Mongolian",
my = "Myanmar (Burmese)",
ne = "Nepali",
no = "Norwegian",
ps = "Pashto",
fa = "Persian",
pl = "Polish",
pt = "Portuguese",
pa = "Punjabi",
ro = "Romanian",
ru = "Russian",
sm = "Samoan",
gd = "Scots Gaelic",
sr = "Serbian",
st = "Sesotho",
sn = "Shona",
sd = "Sindhi",
si = "Sinhala",
sk = "Slovak",
sl = "Slovenian",
so = "Somali",
es = "Spanish",
su = "Sundanese",
sw = "Swahili",
sv = "Swedish",
tg = "Tajik",
ta = "Tamil",
te = "Telugu",
th = "Thai",
tr = "Turkish",
uk = "Ukrainian",
ur = "Urdu",
uz = "Uzbek",
vi = "Vietnamese",
cy = "Welsh",
xh = "Xhosa",
yi = "Yiddish",
yo = "Yoruba",
zu = "Zulu"
};
function find(lang)
for i,v in pairs(languages) do
if i == lang or v == lang then
return i
end
end
end
function isSupported(lang)
local key = find(lang)
return key and true or false
end
function getISOCode(lang)
local key = find(lang)
return key
end
function stringifyQuery(dataFields)
local data = ""
for k, v in pairs(dataFields) do
if type(v) == "table" then
for _,v in pairs(v) do
data = data .. ("&%s=%s"):format(
game.HttpService:UrlEncode(k),
game.HttpService:UrlEncode(v)
)
end
else
data = data .. ("&%s=%s"):format(
game.HttpService:UrlEncode(k),
game.HttpService:UrlEncode(v)
)
end
end
data = data:sub(2)
return data
end
local reqid = math.random(1000,9999)
local rpcidsTranslate = "MkEWBc"
local rootURL = "https://translate.google.com/"
local executeURL = "https://translate.google.com/_/TranslateWebserverUi/data/batchexecute"
local fsid, bl
do -- init
print('initialize')
local InitialReq = got(rootURL)
fsid = InitialReq.Body:match('"FdrFJe":"(.-)"')
bl = InitialReq.Body:match('"cfb2h":"(.-)"')
end
local HttpService = game:GetService("HttpService")
function jsonE(o)
return HttpService:JSONEncode(o)
end
function jsonD(o)
return HttpService:JSONDecode(o)
end
function translate(str, to, from)
reqid+=10000
from = from and getISOCode(from) or 'auto'
to = to and getISOCode(to) or 'en'
local data = {{str, from, to, true}, {nil}}
local freq = {
{
{
rpcidsTranslate,
jsonE(data),
nil,
"generic"
}
}
}
local url = executeURL..'?'..stringifyQuery{rpcids = rpcidsTranslate, ['f.sid'] = fsid, bl = bl, hl="en", _reqid = reqid-10000, rt = 'c'}
local body = stringifyQuery{['f.req'] = jsonE(freq)}
local req = got(url, "POST", body)
local body = jsonD(req.Body:match'%[.-%]\n')
local translationData = jsonD(body[1][3])
local result = {
text = "",
from = {
language = "",
text = ""
},
raw = ""
}
result.raw = translationData
result.text = translationData[2][1][1][6][1][1]
result.from.language = translationData[3]
result.from.text = translationData[2][5][1]
return result
end
local Players = game:GetService("Players")
local LP = Players.LocalPlayer
local StarterGui = game:GetService('StarterGui')
for i=1, 15 do
local r = pcall(StarterGui["SetCore"])
if r then break end
game:GetService('RunService').RenderStepped:wait()
end
wait()
local properties = {
Color = Color3.new(1,1,0);
Font = Enum.Font.SourceSansItalic;
TextSize = 16;
}
game:GetService("StarterGui"):SetCore("SendNotification",
{
Title = "Chat Translator",
Text = "Ported to Google Translate",
Duration = 3
}
)
properties.Text = "[TR] To send messages in a language, say > followed by the target language/language code, e.g.: >ru or >russian. To disable (go back to original language), say >d."
StarterGui:SetCore("ChatMakeSystemMessage", properties)
function translateFrom(message)
local translation = translate(message, YourLang)
local text
if translation.from.language ~= YourLang then
text = translation.text
end
return {text, translation.from.language}
end
function get(plr, msg)
local tab = translateFrom(msg)
local translation = tab[1]
if translation then
properties.Text = "("..tab[2]:upper()..") ".."[".. plr.Name .."]: "..translation
StarterGui:SetCore("ChatMakeSystemMessage", properties)
end
end
for i, plr in ipairs(Players:GetPlayers()) do
plr.Chatted:Connect(function(msg)
get(plr, msg)
end)
end
Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
get(plr, msg)
end)
end)
local sendEnabled = false
local target = ""
function translateTo(message, target)
target = target:lower()
local translation = translate(message, target, "auto")
return translation.text
end
function disableSend()
sendEnabled = false
properties.Text = "[TR] Sending Disabled"
StarterGui:SetCore("ChatMakeSystemMessage", properties)
end
local CBar, CRemote, Connected = LP['PlayerGui']:WaitForChild('Chat')['Frame'].ChatBarParentFrame['Frame'].BoxFrame['Frame'].ChatBar, game:GetService('ReplicatedStorage').DefaultChatSystemChatEvents['SayMessageRequest'], {}
local HookChat = function(Bar)
coroutine.wrap(function()
if not table.find(Connected,Bar) then
local Connect = Bar['FocusLost']:Connect(function(Enter)
if Enter ~= false and Bar['Text'] ~= '' then
local Message = Bar['Text']
Bar['Text'] = '';
if Message == ">d" then
disableSend()
elseif Message:sub(1,1) == ">" and not Message:find(" ") then
if getISOCode(Message:sub(2)) then
sendEnabled = true
target = Message:sub(2)
else
properties.Text = "[TR] Invalid language"
StarterGui:SetCore("ChatMakeSystemMessage", properties)
end
elseif sendEnabled then
Message = translateTo(Message, target)
if not _G.SecureChat then
game:GetService('Players'):Chat(Message);
end
CRemote:FireServer(Message,'All')
else
if not _G.SecureChat then
game:GetService('Players'):Chat(Message);
end
CRemote:FireServer(Message,'All')
end
end
end)
Connected[#Connected+1] = Bar; Bar['AncestryChanged']:Wait(); Connect:Disconnect()
end
end)()
end
HookChat(CBar); local BindHook = Instance.new('BindableEvent')
local MT = getrawmetatable(game); local NC = MT.__namecall; setreadonly(MT, false)
MT.__namecall = newcclosure(function(...)
local Method, Args = getnamecallmethod(), {...}
if rawequal(tostring(Args[1]),'ChatBarFocusChanged') and rawequal(Args[2],true) then
if LP['PlayerGui']:FindFirstChild('Chat') then
BindHook:Fire()
end
end
return NC(...)
end)
BindHook['Event']:Connect(function()
CBar = LP['PlayerGui'].Chat['Frame'].ChatBarParentFrame['Frame'].BoxFrame['Frame'].ChatBar
HookChat(CBar)
end)