Skip to content

Commit

Permalink
Fix: target_language code when deepl
Browse files Browse the repository at this point in the history
  • Loading branch information
jianchang512 committed Oct 29, 2024
1 parent 469a2ae commit fe4b08f
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 13 deletions.
4 changes: 2 additions & 2 deletions videotrans/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-

VERSION = "v2.92"
VERSION_NUM = 120092
VERSION = "v2.94"
VERSION_NUM = 120094
2 changes: 2 additions & 0 deletions videotrans/recognition/_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def _exec(self) -> Union[List[Dict], None]:
if not config.settings['rephrase'] or self.detect_language[:2] !='zh':
jianfan=config.settings.get('zh_hant_s')
for i in alllist:
if len(i['words'])<1:
continue
tmp = {
'text': zhconv.convert(i['text'], 'zh-hans') if jianfan and self.detect_language[:2]=='zh' else i['text'],
'start_time': int(i['words'][0]['start'] * 1000),
Expand Down
9 changes: 8 additions & 1 deletion videotrans/translator/_deepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ def _item_task(self, data: Union[List[str], str]) -> str:

deepltranslator = deepl.Translator(config.params['deepl_authkey'], server_url=self.api_url, proxy=self.proxies)
config.logger.info(f'[DeepL]请求数据:{data=},{config.params["deepl_gid"]=}')
target_code=self.target_code.upper()
if target_code=='EN':
target_code='EN-US'
elif target_code=='ZH-CN':
target_code='ZH-HANS'
elif target_code=='ZH-TW':
target_code='ZH-HANT'
result = deepltranslator.translate_text(
"\n".join(data),
source_lang=self.source_code.upper()[:2] if self.source_code else None,
target_lang='EN-US' if self.target_code.lower() == 'en' else self.target_code,
target_lang=target_code,
glossary=config.params['deepl_gid'] if config.params['deepl_gid'] else None
)

Expand Down
9 changes: 8 additions & 1 deletion videotrans/translator/_deeplx.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,17 @@ def __init__(self, *args, **kwargs):
self.proxies = {"http": "", "https": ""}

def _item_task(self, data: Union[List[str], str]) -> str:
target_code=self.target_code.upper()
if target_code=='EN':
target_code='EN-US'
elif target_code=='ZH-CN':
target_code='ZH-HANS'
elif target_code=='ZH-TW':
target_code='ZH-HANT'
jsondata = {
"text": "\n".join(data),
"source_lang": self.source_code.upper()[:2] if self.source_code else None,
"target_lang": 'EN-US' if self.target_code.lower() == 'en' else self.target_code
"target_lang": target_code
}
config.logger.info(f'[DeepLX]发送请求数据,{jsondata=}')
response = requests.post(url=self.api_url, json=jsondata, proxies=self.proxies)
Expand Down
1 change: 1 addition & 0 deletions videotrans/ui/en.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ def setupUi(self, MainWindow):
self.voice_rate = QtWidgets.QSpinBox(self.layoutWidget)
self.voice_rate.setMinimum(-50)
self.voice_rate.setMaximum(50)
self.voice_rate.setMinimumSize(QtCore.QSize(50, 30))
self.voice_rate.setObjectName("voice_rate")

self.layout_voice_rate.setAlignment(Qt.AlignVCenter)
Expand Down
2 changes: 1 addition & 1 deletion videotrans/winform/ai302.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def run(self):
try:
raw = "你好啊我的朋友"
text = translator.run(translate_type=translator.AI302_INDEX, text_list=raw,
target_language_name="English" if config.defaulelang != 'zh' else "英语",
target_code="en",
source_code="zh-cn",
is_test=True)
self.uito.emit(f"ok:{raw}\n{text}")
Expand Down
2 changes: 1 addition & 1 deletion videotrans/winform/baidu.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def run(self):
text = translator.run(translate_type=translator.BAIDU_INDEX,
text_list=raw,
source_code="zh-cn",
target_language_name="en", is_test=True)
target_code="en", is_test=True)
self.uito.emit(f"ok:{raw}\n{text}")
except Exception as e:
self.uito.emit(str(e))
Expand Down
2 changes: 1 addition & 1 deletion videotrans/winform/chatgpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def run(self):
try:
raw = "你好啊我的朋友"
text = translator.run(translate_type=translator.CHATGPT_INDEX, text_list=raw,
target_language_name="English" if config.defaulelang != 'zh' else "英语",
target_code="en",
source_code="zh",
is_test=True)
self.uito.emit(f"ok:{raw}\n{text}")
Expand Down
2 changes: 1 addition & 1 deletion videotrans/winform/deepL.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def run(self):
raw = "你好啊我的朋友"
text = translator.run(translate_type=translator.DEEPL_INDEX,
text_list=raw,
target_language_name="en",
target_code="en",
source_code="zh-cn",
is_test=True)
self.uito.emit(f"ok:{raw}\n{text}")
Expand Down
2 changes: 1 addition & 1 deletion videotrans/winform/deepLX.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def run(self):
text = translator.run(translate_type=translator.DEEPLX_INDEX,
text_list=raw,
source_code="zh-cn",
target_language_name="en",
target_code="en",
is_test=True)
self.uito.emit(f"ok:{raw}\n{text}")
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion videotrans/winform/localllm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def run(self):
raw = "你好啊我的朋友"
text = translator.run(translate_type=translator.LOCALLLM_INDEX,
text_list=raw,
target_language_name="English" if config.defaulelang != 'zh' else "英语",
target_code="en",
source_code="zh-cn",
is_test=True)
self.uito.emit(f"ok:{raw}\n{text}")
Expand Down
2 changes: 1 addition & 1 deletion videotrans/winform/tencent.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def run(self):
text = translator.run(translate_type=translator.TENCENT_INDEX,
text_list=raw,
source_code="zh-cn",
target_language_name="en", is_test=True)
target_code="en", is_test=True)
self.uito.emit(f"ok:{raw}\n{text}")
except Exception as e:
self.uito.emit(str(e))
Expand Down
2 changes: 1 addition & 1 deletion videotrans/winform/transapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def run(self):
raw = "你好啊我的朋友"
text = translator.run(translate_type=translator.TRANSAPI_INDEX, text_list=raw,
source_code='zh-cn',
target_language_name="en", is_test=True)
target_code="en", is_test=True)
self.uito.emit(f"ok:{raw}\n{str(text)}")
except Exception as e:
self.uito.emit(str(e))
Expand Down
2 changes: 1 addition & 1 deletion videotrans/winform/zijiehuoshan.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def run(self):
try:
raw = "你好啊我的朋友"
text = translator.run(translate_type=translator.ZIJIE_INDEX, text_list=raw,
target_language_name="英语" if config.defaulelang=='zh' else 'English',
target_code="en",
source_code="zh-cn",
is_test=True)
self.uito.emit(f"ok:{raw}\n{text}")
Expand Down

0 comments on commit fe4b08f

Please sign in to comment.