translate plugin works now
This commit is contained in:
		@@ -1,17 +1,21 @@
 | 
			
		||||
 | 
			
		||||
--[[
 | 
			
		||||
-- Translate text using Google Translate.
 | 
			
		||||
-- http://translate.google.com/translate_a/t?client=z&ie=UTF-8&oe=UTF-8&hl=en&tl=en&text=hello
 | 
			
		||||
-- http://translate.google.com/translate_a/single?client=t&ie=UTF-8&oe=UTF-8&hl=en&dt=t&tl=en&sl=auto&text=hello
 | 
			
		||||
--]]
 | 
			
		||||
do
 | 
			
		||||
 | 
			
		||||
function translate(source_lang, target_lang, text)
 | 
			
		||||
  local path = "http://translate.google.com/translate_a/t"
 | 
			
		||||
  local path = "http://translate.google.com/translate_a/single"
 | 
			
		||||
  -- URL query parameters
 | 
			
		||||
  local params = {
 | 
			
		||||
    client = "z", -- JSON
 | 
			
		||||
    client = "t",
 | 
			
		||||
    ie = "UTF-8",
 | 
			
		||||
    oe = "UTF-8",
 | 
			
		||||
    hl = "de",
 | 
			
		||||
    dt = "t",
 | 
			
		||||
    tl = target_lang or "de",
 | 
			
		||||
    sl = source_lang or "",
 | 
			
		||||
    sl = source_lang or "auto",
 | 
			
		||||
    text = URL.escape(text)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -19,21 +23,11 @@ function translate(source_lang, target_lang, text)
 | 
			
		||||
  local url = path..query
 | 
			
		||||
 | 
			
		||||
  local res, code = https.request(url)
 | 
			
		||||
  if res == nil then
 | 
			
		||||
    return 'Text kann momentan nicht <20>bersetzt werden. Probiere es sp<73>ter erneut. URL: '..url
 | 
			
		||||
  end
 | 
			
		||||
  -- Return nil if error
 | 
			
		||||
  if code > 200 then return nil end
 | 
			
		||||
  
 | 
			
		||||
  local trans = json:decode(res)
 | 
			
		||||
  
 | 
			
		||||
  local sentences = ""
 | 
			
		||||
  -- Join multiple sencentes
 | 
			
		||||
  for k,sentence in pairs(trans.sentences) do
 | 
			
		||||
    sentences = sentences..sentence.trans..'\n'
 | 
			
		||||
  end
 | 
			
		||||
  local trans = res:gmatch("%[%[%[\"(.*)\"")():gsub("\"(.*)", "")
 | 
			
		||||
 | 
			
		||||
  return sentences
 | 
			
		||||
  return trans
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function run(msg, matches)
 | 
			
		||||
@@ -52,7 +46,7 @@ function run(msg, matches)
 | 
			
		||||
    return translate(nil, target, text)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  -- Frist pattern
 | 
			
		||||
  -- First pattern
 | 
			
		||||
  if #matches == 3 then
 | 
			
		||||
    print("Third")
 | 
			
		||||
    local source = matches[1]
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user