Skip to content

Instantly share code, notes, and snippets.

@andilabs
Created June 9, 2015 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andilabs/7a8d14cc97a623904160 to your computer and use it in GitHub Desktop.
Save andilabs/7a8d14cc97a623904160 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
from apiclient.discovery import build
from django.conf import settings
def translate(word, from_l, to_l):
if isinstance(word, unicode) is False:
word = unicode(word, 'utf-8')
service = build(
'translate',
'v2',
developerKey=settings.GOOGLE_API_KEY)
return service.translations().list(
source=from_l,
target=to_l,
q=[word]
).execute()['translations'][0]['translatedText']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment