Skip to content

Commit

Permalink
feat: fixing mistakes
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonNotJson committed Jan 2, 2023
1 parent c9b3a53 commit 18e89f0
Showing 1 changed file with 0 additions and 45 deletions.
45 changes: 0 additions & 45 deletions src/lambda/post-comment/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,48 +48,3 @@ def api_response(code, body):
"multiValueHeaders": {"Access-Control-Allow-Methods": ["POST", "OPTIONS", "GET", "PATCH", "DELETE"]},
"body": body
}


def resp_handler(func=None, headers=None):
def handle(*args, **kwargs):
try:
resp = func(*args, **kwargs)
return api_response(200, resp)
except LookupError:
resp = JsonPayloadBuilder().add_status(False).add_data(None) \
.add_message("Not found").compile()
return api_response(404, resp)
except Exception as e:
logging.error(str(e))
resp = JsonPayloadBuilder().add_status(False).add_data(None) \
.add_message("Internal error, please contact [email protected].").compile()
return api_response(500, resp)

return handle


def translate_text(text):
src_lang = client.detect_language(request={
"parent": parent,
"content": text,
"mime_type": "text/plain"
}).languages[0].language_code

translations = {}

for lang in langs:
if lang == src_lang:
translations[lang] = text
continue

translated = client.translate_text(request={
"parent": parent,
"contents": [text],
"mime_type": "text/plain",
"source_language_code": src_lang,
"target_language_code": lang
}).translations[0].translated_text

translations[lang] = translated or ''

return src_lang, translations

0 comments on commit 18e89f0

Please sign in to comment.