Advertisement
CapsAdmin

Untitled

Jan 17th, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.57 KB | None | 0 0
  1. local function escape(s)
  2.     return string.gsub(s, "([^A-Za-z0-9_])", function(c)
  3.         return string.format("%%%02x", string.byte(c))
  4.     end)
  5. end
  6.  
  7. local function geturl(str, to, from)
  8.     from = from or "en"
  9.     assert(str)
  10.     assert(to)
  11.     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)
  12. end
  13.  
  14. local function translate(str, from, to, callback)
  15.     http.Fetch(geturl(str, to, from), function(data)
  16.         local res = data:match("%[%[%[\"(.-)\"")
  17.         callback(res)
  18.     end)
  19. end
  20.  
  21. google_translate = translate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement