 #
 # translate me <phrase> - Searches for a translation for the <phrase> and then
 #                         prints that bad boy out.
+#
+# translate me from <source> into <target> <phrase> - Translates <phrase> from <source> into <target>. Both <source> and <target> are optional
+#
+
 languages =
   "af":"Afrikaans",
   "sq":"Albanian",

  "vi":"Vietnamese",
  "cy":"Welsh",
  "yi":"Yiddish"

module.exports = (robot) ->
  robot.respond /(translate)( me)? (.*)/i, (msg) ->
    term   = "\"#{msg.match[3]}\""

    msg.http("http://translate.google.com/translate_a/t")
      .query({
        client: 't'
        hl: 'en'
        multires: 1
        sc: 1
        sl: 'auto'
        ssel: 0
        tl: 'en'
        tsel: 0
        uptl: "en"
        text: term

        data   = body
        if data.length > 4 && data[0] == '['
          parsed = eval(data)
          language =languages[parsed[2]]
          parsed = parsed[0] && parsed[0][0] && parsed[0][0][0]
          if parsed
            if msg.match[9] is undefined
              msg.send "#{term} is #{language} for #{parsed}"
            else
              msg.send "The #{language} #{term} translates as #{parsed} in #{languages[target]}"

