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