--[[
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('') do
local k,v = match:match('')
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 = syn.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",-- > keybind
af = "Afrikaans",-- > keybind
sq = "Albanian",-- > keybind
am = "Amharic",-- > keybind
ar = "Arabic",-- > keybind
hy = "Armenian",-- > keybind
az = "Azerbaijani",-- > keybind
eu = "Basque",-- > keybind
be = "Belarusian",-- > keybind
bn = "Bengali",-- > keybind
bs = "Bosnian",-- > keybind
bg = "Bulgarian",-- > keybind
ca = "Catalan",-- > keybind
ceb = "Cebuano",-- > keybind
ny = "Chichewa",-- > keybind
['zh-cn'] = "Chinese Simplified",-- > keybind
['zh-tw'] = "Chinese Traditional",-- > keybind
co = "Corsican",-- > keybind
hr = "Croatian",-- > keybind
cs = "Czech",-- > keybind
da = "Danish",-- > keybind
nl = "Dutch",-- > keybind
en = "English",-- > keybind
eo = "Esperanto",-- > keybind
et = "Estonian",-- > keybind
tl = "Filipino",-- > keybind
fi = "Finnish",-- > keybind
fr = "French",-- > keybind
fy = "Frisian",-- > keybind
gl = "Galician",-- > keybind
ka = "Georgian",-- > keybind
de = "German",-- > keybind
el = "Greek",-- > keybind
gu = "Gujarati",-- > keybind
ht = "Haitian Creole",-- > keybind
ha = "Hausa",-- > keybind
haw = "Hawaiian",-- > keybind
iw = "Hebrew",-- > keybind
hi = "Hindi",-- > keybind
hmn = "Hmong",-- > keybind
hu = "Hungarian",-- > keybind
is = "Icelandic",-- > keybind
ig = "Igbo",-- > keybind
id = "Indonesian",-- > keybind
ga = "Irish",-- > keybind
it = "Italian",-- > keybind
ja = "Japanese",-- > keybind
jw = "Javanese",-- > keybind
kn = "Kannada",-- > keybind
kk = "Kazakh",-- > keybind
km = "Khmer",-- > keybind
ko = "Korean",-- > keybind
ku = "Kurdish (Kurmanji)",-- > keybind
ky = "Kyrgyz",-- > keybind
lo = "Lao",-- > keybind
la = "Latin",-- > keybind
lv = "Latvian",-- > keybind
lt = "Lithuanian",-- > keybind
lb = "Luxembourgish",-- > keybind
mk = "Macedonian",-- > keybind
mg = "Malagasy",-- > keybind
ms = "Malay",-- > keybind
ml = "Malayalam",-- > keybind
mt = "Maltese",-- > keybind
mi = "Maori",-- > keybind
mr = "Marathi",-- > keybind
mn = "Mongolian",-- > keybind
my = "Myanmar (Burmese)",-- > keybind
ne = "Nepali",-- > keybind
no = "Norwegian",-- > keybind
ps = "Pashto",-- > keybind
fa = "Persian",-- > keybind
pl = "Polish",-- > keybind
pt = "Portuguese",-- > keybind
pa = "Punjabi",-- > keybind
ro = "Romanian",-- > keybind
ru = "Russian",-- > keybind
sm = "Samoan",-- > keybind
gd = "Scots Gaelic",-- > keybind
sr = "Serbian",-- > keybind
st = "Sesotho",-- > keybind
sn = "Shona",-- > keybind
sd = "Sindhi",-- > keybind
si = "Sinhala",-- > keybind
sk = "Slovak",-- > keybind
sl = "Slovenian",-- > keybind
so = "Somali",-- > keybind
es = "Spanish",-- > keybind
su = "Sundanese",-- > keybind
sw = "Swahili",-- > keybind
sv = "Swedish",-- > keybind
tg = "Tajik",-- > keybind
ta = "Tamil",-- > keybind
te = "Telugu",-- > keybind
th = "Thai",-- > keybind
tr = "Turkish",-- > keybind
uk = "Ukrainian",-- > keybind
ur = "Urdu",-- > keybind
uz = "Uzbek",-- > keybind
vi = "Vietnamese",-- > keybind
cy = "Welsh",-- > keybind
xh = "Xhosa",-- > keybind
yi = "Yiddish",-- > keybind
yo = "Yoruba",-- > keybind
zu = "Zulu"-- > keybind
};
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)