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