Skip to content

Commit

Permalink
<fix> fix always show web_brower window in one-key-translate even use…
Browse files Browse the repository at this point in the history
… other translation engines

update version to v2.4.0
  • Loading branch information
anonymousException committed Jun 11, 2024
1 parent 909fb47 commit af16e4d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 36 deletions.
3 changes: 2 additions & 1 deletion src/editor_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -1526,8 +1526,9 @@ def update_progress(self):
rpy_info_dic.clear()
self.is_waiting_translated = False
translated_dic = []
return
rpy_info_dic.clear()
if os.path.isfile(web_brower_export_name):
os.remove(web_brower_export_name)
else:
editor_main_trhead_lock.release()

Expand Down
4 changes: 3 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
sourceDic = dict()
translator = QTranslator()

VERSION = '2.3.9'
VERSION = '2.4.0'


class MyProxyForm(QDialog, Ui_ProxyDialog):
Expand Down Expand Up @@ -633,6 +633,8 @@ def update_progress(self, data):
self.is_current, is_replace_special_symbols, i, ret, dic)
rpy_info_dic.clear()
self.is_waiting_translated = False
if os.path.isfile(web_brower_export_name):
os.remove(web_brower_export_name)

if self.extracting:
if self.myExtractionForm is not None:
Expand Down
75 changes: 42 additions & 33 deletions src/one_key_translate_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from custom_engine_form import sourceDic, targetDic
from my_log import log_print
from renpy_translate import engineDic, language_header, translateThread, translate_threads, get_translated_dic, \
web_brower_export_name, rpy_info_dic, get_rpy_info, web_brower_translate
web_brower_export_name, rpy_info_dic, get_rpy_info, web_brower_translate, engineList
from engine_form import MyEngineForm
from game_unpacker_form import finish_flag
from extract_runtime_form import extract_finish
Expand Down Expand Up @@ -652,39 +652,48 @@ def update_progress(self):
self.qDic.pop(func, None)
if func == self.translate:
global rpy_info_dic
webbrowser.open(web_brower_export_name)
translated_form = MyTranslatedForm()
translated_form.exec()
f = io.open('translated.txt', 'w', encoding='utf-8')
f.write(translated_form.plainTextEdit.toPlainText())
f.close()
dic, is_replace_special_symbols = get_translated_dic(web_brower_export_name, 'translated.txt')
if dic is None:
msg_box = QMessageBox()
msg_box.setWindowTitle('o(≧口≦)o')
msg_box.setText(
QCoreApplication.translate('ImportHtmlDialog',
'The html file does not match the translated file , please check the input files',
None))
msg_box.exec()
rpy_info_dic.clear()
else:
if self.select_dir is not None and os.path.isdir(self.select_dir):
paths = os.walk(self.select_dir, topdown=False)
for path, dir_lst, file_lst in paths:
for file_name in file_lst:
i = path + '/' + file_name
if not file_name.endswith("rpy"):
continue
if i in rpy_info_dic.keys():
ret, unmatch_cnt, p = rpy_info_dic[i]
if os.path.isfile('engine.txt'):
with open('engine.txt', 'r', encoding='utf-8') as json_file:
loaded_data = json.load(json_file)
if loaded_data['engine'] == engineList[12]:
if os.path.isfile(web_brower_export_name):
webbrowser.open(web_brower_export_name)
translated_form = MyTranslatedForm()
translated_form.exec()
f = io.open('translated.txt', 'w', encoding='utf-8')
f.write(translated_form.plainTextEdit.toPlainText())
f.close()
dic, is_replace_special_symbols = get_translated_dic(web_brower_export_name, 'translated.txt')
if dic is None:
msg_box = QMessageBox()
msg_box.setWindowTitle('o(≧口≦)o')
msg_box.setText(
QCoreApplication.translate('ImportHtmlDialog',
'The html file does not match the translated file , please check the input files',
None))
msg_box.exec()
rpy_info_dic.clear()
else:
ret, unmatch_cnt, p = get_rpy_info(i)
rpy_info_dic[i] = ret, unmatch_cnt, p
web_brower_translate(self.filterCheckBox.isChecked(),
self.filterLengthLineEdit.text(), True,
is_replace_special_symbols, i, ret, dic)
rpy_info_dic.clear()
if self.select_dir is not None and os.path.isdir(self.select_dir):
paths = os.walk(self.select_dir, topdown=False)
for path, dir_lst, file_lst in paths:
for file_name in file_lst:
i = path + '/' + file_name
if not file_name.endswith("rpy"):
continue
if i in rpy_info_dic.keys():
ret, unmatch_cnt, p = rpy_info_dic[i]
else:
ret, unmatch_cnt, p = get_rpy_info(i)
rpy_info_dic[i] = ret, unmatch_cnt, p
web_brower_translate(self.filterCheckBox.isChecked(),
self.filterLengthLineEdit.text(), True,
is_replace_special_symbols, i, ret, dic)
rpy_info_dic.clear()
if os.path.isfile(web_brower_export_name):
os.remove(web_brower_export_name)
else:
log_print('nothing to translate')
else:
if not self.is_queue_task_empty:
if len(rpy_info_dic) == 0:
Expand Down
2 changes: 1 addition & 1 deletion src/renpy_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def init_client():
del os.environ['HTTP_PROXY']
os.environ['NO_PROXY'] = '*'
if os.path.isfile('engine.txt'):
with open('engine.txt', 'r') as json_file:
with open('engine.txt', 'r', encoding='utf-8') as json_file:
loaded_data = json.load(json_file)
if loaded_data['engine'] == engineList[0]:
client = Translate(fmt='text', proxies=proxies)
Expand Down

0 comments on commit af16e4d

Please sign in to comment.