 # an array of languages to translate text through
 # wraps LOCAL_LANGUAGE around random assortment of languages
 getTranslationPath = (garbleAmount) ->
-  _.chain(getRandomLanguages(getLanguageCodes(), garbleAmount))
+  path = _.chain(getRandomLanguages(getLanguageCodes(), garbleAmount))
     .unshift(LOCAL_LANGUAGE)
     .push(LOCAL_LANGUAGE)
+    .value()
+  # no doubt there is a better way to do this
+  pairs = _.chain(path)
+    .map((lang, i) -> [lang, path[i+1]])
+    .dropRight(1)
     .value()
 
 # a string that indicates what "translation path" the text was passed through
 getTranslationPathLog = (languageCodes) ->
-  languageNames = _.map languageCodes, (code) -> getLanguageName(code)
+  languageNames = _.map languageCodes, (code) ->
+    getLanguageName(code[0])
+  languageNames.push(getLanguageName(LOCAL_LANGUAGE))
   "translation path: #{languageNames.join(' → ')}"
 
 # a URI that satisfies the Yandex API requirements


    langs = getTranslationPath(garbleAmount)

    if text?.length

      request getRequestURI(langs[0], langs[1], text), (error, response, body) ->
        request getRequestURI(langs[1], langs[2], parseResponse(body)), (error, response, body) ->
          request getRequestURI(langs[2], langs[3], parseResponse(body)), (error, response, body) ->
            request getRequestURI(langs[3], langs[4], parseResponse(body)), (error, response, body) ->
              request getRequestURI(langs[4], langs[5], parseResponse(body)), (error, response, body) ->
                request getRequestURI(langs[5], langs[6], parseResponse(body)), (error, response, body) ->
                  msg.send parseResponse(body)
                  unless SHOW_TRANSLATION_PATH == 'false'
                    msg.send getTranslationPathLog(langs)

    text: text
  return "#{TRANSLATE_URI}?#{querystring.stringify(opts)}"

# returns request promise
getTranslation = (fromLang, toLang, text) ->
  request getRequestURI(fromLang, toLang, text)

# a string of translated text
parseResponse = (str) ->
  try
    return JSON.parse(str).text[0]
  catch e
    return str

module.exports = (robot) ->

