Created
July 21, 2020 15:25
-
-
Save armindocachada/de7079c29d31f8f1af5c41f09acdfe16 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
def translate(text,language): | |
from google.cloud import translate_v2 as translate | |
translate_client = translate.Client() | |
if isinstance(text, bytes): | |
text = text.decode('utf-8') | |
# Text can also be a sequence of strings, in which case this method | |
# will return a sequence of results for each text. | |
result = translate_client.translate( | |
text, target_language=language) | |
print(u'Text: {}'.format(result['input'])) | |
print(u'Translation: {}'.format(result['translatedText'])) | |
print(u'Detected source language: {}'.format( | |
result['detectedSourceLanguage']) | |
) | |
return result['translatedText'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment