Commits

Jason R. Coombs committed 2400b57

Tested protocol and the basic tests work

Comments (0)

Files changed (2)

jaraco/translate/google.py

 	"""
 	url_base = 'https://www.googleapis.com/language/translate/v2'
 	params = dict(
-		key = translate.API_KEY,
+		key = translate.API_key,
 		q = text,
 		target = target_lang,
 	)
 	if source_lang:
 		params['source'] = source_lang
 	u = urllib2.urlopen(url_base + '?' + urllib.urlencode(params))
-	return json.loads(u.read())['data']['translations']['translatedText']
+	data = u.read()
+	return json.loads(data)['data']['translations'][0]['translatedText']

jaraco/translate/pmxbot.py

 from . import google
-from pmxbot.botbase import command
+import pmxbot.botbase
 
-@command("translate", aliases=('trans', 'googletrans', 'googletranslate'),
+google.translate.API_KEY = pmxbot.config.google_translate_API_key
+
+@pmxbot.botbase.command("translate",
+	aliases=('trans', 'googletrans', 'googletranslate'),
 	doc="Translate a phrase using Google Translate. First argument should be "
 		"the language[s]. It is a 2 letter abbreviation. It will auto detect "
 		"the orig lang if you only give one; or two languages joined by a |, "
 	The translate function should be able to translate a simple string.
 	"""
 	query = '|en que no desea la nueva pregunta'
-	res = translate(c, e, '#test', 'testrunner', query)
+	res = translate(None, None, '#test', 'testrunner', query)
 	assert 'new question' in res.lower()
 	query = 'es|en que no desea la nueva pregunta'
-	res = translate(c, e, '#test', 'testrunner', query)
+	res = translate(None, None, '#test', 'testrunner', query)
 	assert 'new question' in res.lower()
 
 def test_translate_invalid_lang(self):
 	"""
 	# sp is not a language
 	invalid_query = 'sp|en que no desea la nueva pregunta'
-	res = translate(c, e, '#test', 'testrunner', invalid_query)
+	res = translate(None, None, '#test', 'testrunner', invalid_query)
 	assert 'are you sure' in res.lower()