Created
December 4, 2018 21:34
-
-
Save crazyrohila/9da8edd2867f4dbc24e179bf38ddf8ab to your computer and use it in GitHub Desktop.
lex-translation-blog
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
import boto3 | |
def translate_text(text, to_lang, from_lang='en'): | |
if (from_lang == to_lang or not to_lang): | |
return text | |
client = boto3.client('translate', region_name='us-east-1') | |
response = client.translate_text( | |
Text=text, | |
SourceLanguageCode=from_lang, | |
TargetLanguageCode=to_lang | |
) | |
return response['TranslatedText'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment