恍兮惚兮 e8accb3ca2 .
2025-01-06 18:01:38 +08:00

38 lines
1.1 KiB
Python

from language import Languages
from translator.basetranslator import basetrans
class TS(basetrans):
def inittranslator(self):
_ = self.proxysession.get("https://www.translate.com/machine-translation")
def translate(self, content):
from_language = self.srclang
if from_language == Languages.Auto:
detect_form = {"text_to_translate": content}
r_detect = self.proxysession.post(
"https://www.translate.com/translator/ajax_lang_auto_detect",
data=detect_form,
)
from_language = r_detect.json()["language"]
form_data = {
"text_to_translate": content,
"source_lang": from_language,
"translated_lang": self.tgtlang,
"use_cache_only": "false",
}
r = self.proxysession.post(
"https://www.translate.com/translator/translate_mt", data=form_data
)
try:
data = r.json()
return data["translated_text"]
except:
raise Exception(r)
def langmap(self):
return {Languages.TradChinese: "zh-TW"}