Python ile Google Translate
Python ‘da yazılan bir betik için Google Translate ile çeviri lazım olmuştu. Aşağıdaki fonksyon ile sorun çözülmüş oldu.
def translate(content):
try:
import json
except ImportError:
print(‘You need to install the python-json package’)
sys.exit(1)
url=‘http://ajax.googleapis.com/ajax/services/language/translate?’
params=urlencode( ((‘v’,1.0),(‘langpair’,‘tr|en’),(‘q’,content),) )
url=url+params
content=urlopen(url).read()
try:
trans_dict=json.loads(content)
except AttributeError:
trans_dict=json.read(content)
return unicode(trans_dict['responseData']['translatedText'])








