Advertisement
Ant8893

Fe Chat Translator WRD

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