Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function escape(s)
- return string.gsub(s, "([^A-Za-z0-9_])", function(c)
- return string.format("%%%02x", string.byte(c))
- end)
- end
- local function geturl(str, to, from)
- from = from or "en"
- assert(str)
- assert(to)
- return ("http://translate.google.com/translate_a/t?client=t&text=%s&sl=%s&tl=%s&ie=UTF-8&oe=UTF-8"):format(escape(str), from, to)
- end
- local function translate(str, to, from, callback)
- http.Get(geturl(str, to, from), "", function(data)
- local res = data:match("%[%[%[\"(.-)\"")
- callback(res)
- end)
- end
- local function checkA(ply)
- ply = ply or LocalPlayer()
- return ply == caps or ply == shell or ply == funt or ply == newbieking or ply == kesor or ply == morshmellow or ply == whey
- end
- local function checkB(ply)
- --ply = ply or LocalPlayer()
- --return ply == bubu
- --return not checkA(ply)
- return false
- end
- if CLIENT then
- if checkA() then
- hook.Add("OnPlayerChat", 1, function(ply, str)
- if ply == LocalPlayer() then
- return end
- translate(str, "en", "ja", function(str)
- chat.AddText(ply, color_white, ": ", str)
- hook.Call("OnPlayerChatTranslated", GAMEMODE, ply, str)
- end)
- return true
- end)
- end
- if checkB() then
- hook.Add("OnPlayerChat", 1, function(ply, str)
- if ply == LocalPlayer() then
- return end
- translate(str, "ja", "en", function(str)
- chat.AddText(ply, color_white, ": ", str)
- hook.Call("OnPlayerChatTranslated", GAMEMODE, ply, str)
- end)
- return true
- end)
- end
- usermessage.Hook("tr", function(umr)
- local ply = umr:ReadEntity()
- local out = umr:ReadString()
- local str = umr:ReadString()
- chat.AddText(ply, color_white, ": ", out .. " (" .. str .. ")")
- hook.Call("OnPlayerChatTranslated", GAMEMODE, ply, str)
- end)
- end
- if SERVER then
- hook.Add("PlayerSay", 1, function(ply, str)
- if str:sub(1,1) ~= "!" then
- if checkA(ply) then
- translate(str, "ja", "en", function(out) umsg.Start("tr") umsg.Entity(ply) umsg.String(out) umsg.String(str) umsg.End() end)
- return ""
- end
- if checkB(ply) then
- translate(str, "en", "ja", function(out) umsg.Start("tr") umsg.Entity(ply) umsg.String(out) umsg.String(str) umsg.End() end)
- return ""
- end
- end
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment