Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
HIllya51 committed Aug 24, 2024
1 parent 5921160 commit 50bb730
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 12 deletions.
5 changes: 1 addition & 4 deletions LunaTranslator/LunaTranslator/translator/deepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ def translate_deeplx_internal(self, translateText):
data=postStr,
).json()
try:
try:
return res["result"]["texts"][0]["alternatives"][0]["text"]
except:
return res["result"]["texts"][0]["text"]
return res["result"]["texts"][0]["text"]
except:
raise Exception(res)
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ def langmap(self):

def translate(self, query):
if self.config["usewhich"] == 0:
appid = self.multiapikeycurrent["DeepL-Auth-Key-1"]
self.checkempty(["DeepL-Auth-Key"])
appid = self.multiapikeycurrent["DeepL-Auth-Key"]
endpoint = "https://api-free.deepl.com/v2/translate"
self.checkempty(["DeepL-Auth-Key-1"])
elif self.config["usewhich"] == 1:
self.checkempty(["DeepL-Auth-Key-2"])
appid = self.multiapikeycurrent["DeepL-Auth-Key-2"]
endpoint = "https://api.deepl.com/v2/translate"
self.checkempty(["DeepL-Auth-Key-2"])

headers = {
"Authorization": "DeepL-Auth-Key " + appid,
Expand Down
27 changes: 27 additions & 0 deletions LunaTranslator/LunaTranslator/translator/yandex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from translator.basetranslator import basetrans


class TS(basetrans):

def translate(self, content):

headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 YaBrowser/24.1.5.825 Yowser/2.5 Safari/537.36"
}
params = {
"lang": "{}-{}".format(self.srclang, self.tgtlang),
"text": content,
}
url = "https://browser.translate.yandex.net/api/v1/tr.json/translate"
params = {**{"srv": "browser_video_translation"}, **params}
response = self.proxysession.post(
url=url,
params=params,
data={"maxRetryCount": 2, "fetchAbortTimeout": 500},
headers=headers,
)

try:
return response.json()["text"][0]
except:
raise Exception(response.text)
7 changes: 6 additions & 1 deletion LunaTranslator/files/defaultconfig/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,11 @@
"color": "blue",
"name": "yandex api"
},
"yandex": {
"use": false,
"color": "blue",
"name": "yandex"
},
"qqimt": {
"use": false,
"color": "blue",
Expand Down Expand Up @@ -1894,7 +1899,7 @@
"color": "blue",
"name": "sqlite翻译记录"
},
"deeplapi_integrate": {
"deeplapi-free": {
"type": "api",
"use": false,
"color": "blue",
Expand Down
12 changes: 9 additions & 3 deletions LunaTranslator/files/defaultconfig/translatorsetting.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@
"deepl": {
"args": {
"usewhich": 0,
"github": "https://github.com/OwO-Network/DeepLX",
"api": "http://127.0.0.1:1188/translate"
},
"argstype": {
"github": {
"name": "DeepLX Github",
"type": "label",
"islink": true
},
"api": {
"name": "DeepLX api"
},
Expand Down Expand Up @@ -66,11 +72,11 @@
}
}
},
"deeplapi_integrate": {
"deeplapi-free": {
"args": {
"注册网址": "https://www.deepl.com/translator",
"usewhich": 0,
"DeepL-Auth-Key-1": "",
"DeepL-Auth-Key": "",
"DeepL-Auth-Key-2": "",
"字数统计": "0"
},
Expand All @@ -79,7 +85,7 @@
"type": "label",
"islink": true
},
"DeepL-Auth-Key-1": {
"DeepL-Auth-Key": {
"name": "DeepL-Auth-Key Free"
},
"DeepL-Auth-Key-2": {
Expand Down
2 changes: 1 addition & 1 deletion plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ include(generate_product_version)

set(VERSION_MAJOR 5)
set(VERSION_MINOR 30)
set(VERSION_PATCH 5)
set(VERSION_PATCH 6)

add_library(pch pch.cpp)
target_precompile_headers(pch PUBLIC pch.h)
Expand Down

0 comments on commit 50bb730

Please sign in to comment.