cleanup google translate widget
This commit is contained in:
@@ -2,40 +2,41 @@
|
|||||||
-- data_source = "https://translate.google.com"
|
-- data_source = "https://translate.google.com"
|
||||||
-- type = "widget"
|
-- type = "widget"
|
||||||
-- author = "Andrey Gavrilov"
|
-- author = "Andrey Gavrilov"
|
||||||
-- version = "1.0"
|
-- version = "1.1"
|
||||||
|
|
||||||
local json = require "json"
|
local json = require "json"
|
||||||
|
local uri = "http://translate.googleapis.com/translate_a/single?client=gtx&sl=auto"
|
||||||
local text_from = ""
|
local text_from = ""
|
||||||
|
|
||||||
function on_alarm()
|
function on_resume()
|
||||||
ui:show_text("Tap to enter text")
|
ui:show_text("Tap to enter text")
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_click()
|
function on_click()
|
||||||
ui:show_edit_dialog("Введите текст")
|
ui:show_edit_dialog("Enter text")
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_dialog_action(text)
|
function on_dialog_action(text)
|
||||||
if text == "" or text == -1 then
|
if text == "" or text == -1 then
|
||||||
on_alarm()
|
on_alarm()
|
||||||
else
|
else
|
||||||
text_from = text
|
text_from = text
|
||||||
translate(text)
|
translate(text)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function translate(str)
|
function translate(str)
|
||||||
http:get("http://translate.googleapis.com/translate_a/single?client=gtx&sl=auto".."&tl="..system:get_lang().."&dt=t&q="..str)
|
http:get(uri.."&tl="..system:get_lang().."&dt=t&q="..str)
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_network_result(result)
|
function on_network_result(result)
|
||||||
local t = json.decode(result)
|
local t = json.decode(result)
|
||||||
local text_to = ""
|
local text_to = ""
|
||||||
|
|
||||||
for i, v in ipairs(t[1]) do
|
for i, v in ipairs(t[1]) do
|
||||||
text_to = text_to..v[1]
|
text_to = text_to..v[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
local lang_from = t[3]
|
local lang_from = t[3]
|
||||||
ui:show_lines({text_from.." ("..lang_from..")"}, {text_to})
|
ui:show_lines({text_from.." ("..lang_from..")"}, {text_to})
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user