parent
1b54d9bfe2
commit
2d15cf6a98
@ -0,0 +1,3 @@
|
|||||||
|
google-cloud-translate==2.0.0
|
||||||
|
google-cloud-storage==1.19.1
|
||||||
|
mysql-connector-python==8.0.19
|
||||||
|
Can't render this file because it contains an unexpected character in line 5 and column 4.
|
@ -0,0 +1,19 @@
|
|||||||
|
import six
|
||||||
|
from google.cloud import translate_v2 as translate
|
||||||
|
|
||||||
|
""" text - text to Translate
|
||||||
|
target_lang - Target Language Code (ISO Standard)
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def translate_text(text, target_lang):
|
||||||
|
|
||||||
|
translate_client = translate.Client()
|
||||||
|
|
||||||
|
if isinstance(text, six.binary_type):
|
||||||
|
text = text.decode('utf-8')
|
||||||
|
|
||||||
|
result = translate_client.translate(text, target_language=target_lang, model='nmt')
|
||||||
|
print("Translated Text :: ", result['translatedText'])
|
||||||
|
|
||||||
|
return result['translatedText']
|
||||||
Loading…
Reference in new issue