Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Burekasim/07e9b99de1ea81815552bf8a0c914a52 to your computer and use it in GitHub Desktop.
Save Burekasim/07e9b99de1ea81815552bf8a0c914a52 to your computer and use it in GitHub Desktop.
from googletrans import Translator
from urllib.parse import unquote
def lambda_handler(event, context):
data = event['body'].split('&')
body = ''
for item in data:
tt = item.split('=')
if tt[0] == 'Body':
body = tt[1]
translator = Translator()
if any("\u0590" <= c <= "\u05EA" for c in unquote(body)):
text = translator.translate(unquote(body), dest='en')
print(3)
else:
text = translator.translate(body, dest='he')
return_text = '<?xml version="1.0" encoding="UTF-8"?>\n\
<Response>\n\
<Message>' + text.text + '</Message>\n\
</Response>'
return {'statusCode': 200, 'headers': {'Content-Type': 'text/xml', }, 'body': return_text}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment