Created
June 9, 2015 09:58
-
-
Save andilabs/7a8d14cc97a623904160 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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