Created
May 4, 2024 13:47
-
-
Save fnx4/fda2e4a37cc07a92994cb8d2459658eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from translator.basetranslator import basetrans | |
class TS(basetrans): | |
def translate(self,content): | |
result = "" | |
host = "127.0.0.1" | |
port = "5444" | |
text = content | |
lang_from = "en" | |
lang_to = "ru" | |
try: | |
request = { | |
"q": text, | |
"source": lang_from, | |
"target": lang_to, | |
"format": "text" | |
} | |
adr = "http://" + host + ":" + port + "/translate" | |
response = requests.post(adr, json=request).json() | |
if "error" in response: | |
result = response["error"] | |
else: | |
result = response["translatedText"] | |
except Exception as e: | |
result = print(str(e)) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment