forked from jjminsuh/stack_underflow_frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
translate.py
37 lines (27 loc) · 809 Bytes
/
translate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from flask import Flask, request, jsonify
import googletrans
from googletrans import Translator
app = Flask(__name__)
@app.route('/api', methods=['GET'])
def translate():
Query = str(request.args['Query'])
info_list = []
temp = ''
for i in Query:
print(i)
if i == '|':
info_list += [temp]
temp = ''
else:
temp += i
print(info_list)
init = info_list[0]
text = info_list[1]
fin = info_list[2]
translator = Translator()
translation = translator.translate(text, src= init, dest= fin)
print(f"{translation.origin} ({translation.src}) --> {translation.text} ({translation.dest})")
d = {}
d['Query'] = str(translation.text)
return jsonify(d)
#return translation.text