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 check(ply)
- ply = ply or LocalPlayer()
- return ply == caps or ply == shell or ply == funt or ply == newbieking
- end
- if CLIENT then
- if check() 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) 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 .. ")")
- end)
- end
- if SERVER then
- hook.Add("PlayerSay", 1, function(ply, str)
- if check(ply) and str:sub(1,1) ~= "!" then
- translate(str, "ja", "en", function(out) umsg.Start("tr") umsg.Entity(ply) umsg.String(out) umsg.String(str) umsg.End() end)
- return ""
- end
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment