-
-
Save ur4ltz/b6744e1c5ef733c98980f776c962ff6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require("json"); | |
require("socket.http") | |
require("socket.url") | |
function babelfish(lang, query) | |
lang = lang or "en" | |
query = query or "" | |
if lang == "en" or query == "" then | |
return query | |
end | |
local result, status = socket.http.request( | |
"http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" | |
.. socket.url.escape(query) | |
.. "&langpair=en|" | |
.. lang | |
) | |
if not (status == 200 or status == 201) then | |
return "api error: " .. status | |
end | |
local data = json.decode(result) | |
if data.responseStatus == 200 then | |
return data.responseData.translatedText | |
else | |
return "status " .. data.responseStatus .. ": " .. data.responseDetails | |
end | |
end | |
local text = babelfish(arg[1], arg[2]) | |
print(text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment