Advertisement
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, from, to, callback)
- http.Fetch(geturl(str, to, from), function(data)
- local res = data:match("%[%[%[\"(.-)\"")
- callback(res)
- end)
- end
- google_translate = translate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement