Demo entry 6166071

Google Translate API

   

Submitted by neptunius on Oct 07, 2016 at 20:40
Language: Python. Code size: 595 Bytes.

import httplib2
import urllib
import json

GOOGLE_API_KEY = "---"
GOOGLE_TRANSLATE_URL = "https://www.googleapis.com/language/translate/v2"
# params: ?key=$GOOGLE_API_KEY&source=en&target=es&q=Hello%20world"

url = GOOGLE_TRANSLATE_URL + "?key=" + GOOGLE_API_KEY
url += "&source=en"
url += "&target=es"
url += "&q=" + urllib.quote_plus("Hello world")

http = httplib2.Http()
response, body = http.request(url)

print response
print body

content = json.loads(body)
print content

translatedText = content['data']['translations'][0]['translatedText']
print translatedText

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).