Skip to content

Instantly share code, notes, and snippets.

@crazyrohila
Created December 4, 2018 21:34
Show Gist options
  • Save crazyrohila/9da8edd2867f4dbc24e179bf38ddf8ab to your computer and use it in GitHub Desktop.
Save crazyrohila/9da8edd2867f4dbc24e179bf38ddf8ab to your computer and use it in GitHub Desktop.
lex-translation-blog
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