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