-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTranslator.py
More file actions
27 lines (24 loc) · 1.09 KB
/
Translator.py
File metadata and controls
27 lines (24 loc) · 1.09 KB
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
# -*- coding: utf-8 -*-
import pdb
import json
from googletrans import Translator
import goslate
import requests
from yandex_translate import YandexTranslate
translate = YandexTranslate('trnsl.1.1.20171210T144242Z.15fcdfc3fb78b303.0505cd3e5105cc8f96e30350651e309acd643605')
# def translate(text, src="vi", dest="en"):
# # translator = Translator()
# # text_translated = translator.translate(text, dest = dest)
# # return text_translated.text
# gs = goslate.Goslate()
# text_translated = gs.translate(text, dest)
# return text_translated
def translate_yandex(text, src="vi", dest="en"):
text = text.replace('_', ' ')
response = requests.get('https://translate.yandex.net/api/v1.5/tr.json/translate?key=trnsl.1.1.20171210T144242Z.15fcdfc3fb78b303.0505cd3e5105cc8f96e30350651e309acd643605&lang=' +src + '-' + dest +'&text=' + text)
response_json = json.loads(response.content)
return (response_json['text'][0]).replace('"', '')
# def translate_yandex(text):
# response = translate.translate(text, 'vi-en')
# translated = response['text'][0]
# return translated