-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello.py
More file actions
executable file
·29 lines (22 loc) · 775 Bytes
/
Copy pathhello.py
File metadata and controls
executable file
·29 lines (22 loc) · 775 Bytes
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
from flask import Flask, render_template
from google.cloud import translate
app = Flask(__name__)
@app.route('/')
def usage():
client = translate.Client()
languages = client.get_languages()
return render_template('usage.html', languages=languages)
@app.route("/hello/<language>")
def translate_hello_world(language):
"""Translates text into the target language.
Target must be an ISO 639-1 language code.
See https://g.co/cloud/translate/v2/translate-reference#supported_languages
"""
translate_client = translate.Client()
text = "Hello World"
result = translate_client.translate(
text, target_language=language
)
return result['translatedText']
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5001)