Skip to content

Commit

Permalink
<feature> support replace special symbols option for all translation …
Browse files Browse the repository at this point in the history
…engine

update version to v2.4.3
  • Loading branch information
anonymousException committed Jul 6, 2024
1 parent 3893b12 commit 9cb30b2
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 99 deletions.
19 changes: 12 additions & 7 deletions src/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ def setupUi(self, EditorDialog):

self.gridLayout.addWidget(self.widget, 0, 1, 1, 1)

self.tableVerticalLayout = QVBoxLayout()
self.tableVerticalLayout.setObjectName(u"tableVerticalLayout")

self.gridLayout.addLayout(self.tableVerticalLayout, 1, 2, 3, 2)

self.widget_2 = QWidget(EditorDialog)
self.widget_2.setObjectName(u"widget_2")
self.widget_2.setMinimumSize(QSize(680, 360))
Expand All @@ -99,7 +94,7 @@ def setupUi(self, EditorDialog):
self.label_3.setMaximumSize(QSize(16777215, 20))
self.saveFileButton = QPushButton(self.widget_2)
self.saveFileButton.setObjectName(u"saveFileButton")
self.saveFileButton.setGeometry(QRect(140, 100, 335, 24))
self.saveFileButton.setGeometry(QRect(4, 130, 671, 24))
self.saveFileButton.setMaximumSize(QSize(16777215, 24))
self.untranslatedCheckBox = QCheckBox(self.widget_2)
self.untranslatedCheckBox.setObjectName(u"untranslatedCheckBox")
Expand All @@ -111,7 +106,7 @@ def setupUi(self, EditorDialog):
self.originalRadioButton.setMaximumSize(QSize(16777215, 20))
self.label_4 = QLabel(self.widget_2)
self.label_4.setObjectName(u"label_4")
self.label_4.setGeometry(QRect(0, 130, 601, 231))
self.label_4.setGeometry(QRect(0, 160, 671, 201))
self.label_4.setAlignment(Qt.AlignCenter)
self.label_4.setWordWrap(True)
self.searchedOnlyCheckBox = QCheckBox(self.widget_2)
Expand Down Expand Up @@ -156,6 +151,10 @@ def setupUi(self, EditorDialog):
self.filterCheckBox.setObjectName(u"filterCheckBox")
self.filterCheckBox.setGeometry(QRect(20, 75, 301, 20))
self.filterCheckBox.setChecked(True)
self.replaceCheckBox = QCheckBox(self.widget_2)
self.replaceCheckBox.setObjectName(u"replaceCheckBox")
self.replaceCheckBox.setGeometry(QRect(20, 100, 651, 20))
self.replaceCheckBox.setChecked(True)

self.gridLayout.addWidget(self.widget_2, 0, 2, 1, 2)

Expand All @@ -164,6 +163,11 @@ def setupUi(self, EditorDialog):

self.gridLayout.addLayout(self.fileVerticalLayout, 1, 1, 3, 1)

self.tableVerticalLayout = QVBoxLayout()
self.tableVerticalLayout.setObjectName(u"tableVerticalLayout")

self.gridLayout.addLayout(self.tableVerticalLayout, 1, 2, 3, 2)


self.retranslateUi(EditorDialog)

Expand Down Expand Up @@ -203,5 +207,6 @@ def retranslateUi(self, EditorDialog):
self.autoCopyCheckBox.setText(QCoreApplication.translate("EditorDialog", u"Auto copy to Current after translation", None))
self.label_14.setText(QCoreApplication.translate("EditorDialog", u"filter length less than", None))
self.filterCheckBox.setText(QCoreApplication.translate("EditorDialog", u"Enable filter for translate", None))
self.replaceCheckBox.setText(QCoreApplication.translate("EditorDialog", u"Enable replace special symbols", None))
# retranslateUi

34 changes: 25 additions & 9 deletions src/editor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,6 @@
</widget>
</widget>
</item>
<item row="1" column="2" rowspan="3" colspan="2">
<layout class="QVBoxLayout" name="tableVerticalLayout"/>
</item>
<item row="0" column="2" colspan="2">
<widget class="QWidget" name="widget_2" native="true">
<property name="minimumSize">
Expand Down Expand Up @@ -280,9 +277,9 @@
<widget class="QPushButton" name="saveFileButton">
<property name="geometry">
<rect>
<x>140</x>
<y>100</y>
<width>335</width>
<x>4</x>
<y>130</y>
<width>671</width>
<height>24</height>
</rect>
</property>
Expand Down Expand Up @@ -338,9 +335,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>130</y>
<width>601</width>
<height>231</height>
<y>160</y>
<width>671</width>
<height>201</height>
</rect>
</property>
<property name="text">
Expand Down Expand Up @@ -531,11 +528,30 @@
<bool>true</bool>
</property>
</widget>
<widget class="QCheckBox" name="replaceCheckBox">
<property name="geometry">
<rect>
<x>20</x>
<y>100</y>
<width>651</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Enable replace special symbols</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</widget>
</item>
<item row="1" column="1" rowspan="3">
<layout class="QVBoxLayout" name="fileVerticalLayout"/>
</item>
<item row="1" column="2" rowspan="3" colspan="2">
<layout class="QVBoxLayout" name="tableVerticalLayout"/>
</item>
</layout>
</widget>
<resources/>
Expand Down
19 changes: 9 additions & 10 deletions src/editor_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,18 +1055,10 @@ def translate(self):
local_glossary = self.local_glossary
transList = []
client = init_client()
is_replace_special_symbols = True
is_replace_special_symbols = self.editorForm.replaceCheckBox.isChecked()
if isinstance(client, str) and client == 'web_brower':
target_language = None
source_language = None
reply = QMessageBox.question(self,
'o((>ω< ))o',
QCoreApplication.translate('EditorDialog',
'Do you want to replace special symbols?',
None),
QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
if reply != QMessageBox.Yes:
is_replace_special_symbols = False
else:
target_language = targetDic[self.editorForm.targetComboBox.currentText()]
source_language = sourceDic[self.editorForm.sourceComboBox.currentText()]
Expand All @@ -1084,7 +1076,14 @@ def translate(self):
if local_glossary is not None:
for original, replace in local_glossary.items():
target = target.replace(original, replace)
d = EncodeBrackets(target)
if is_replace_special_symbols:
d = EncodeBrackets(target)
else:
d = dict()
d['en_1'] = []
d['en_2'] = []
d['en_3'] = []
d['encoded'] = target
strip_i = target
for j in (d['en_1']):
strip_i = strip_i.replace(j, '')
Expand Down
10 changes: 5 additions & 5 deletions 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.4.2'
VERSION = '2.4.3'


class MyProxyForm(QDialog, Ui_ProxyDialog):
Expand Down Expand Up @@ -499,7 +499,7 @@ def init_combobox(self):
targetDic.clear()
sourceDic.clear()
self.frame.setFixedSize(0, 0)
self.widget.setMinimumSize(600, 480)
self.widget.setMinimumSize(600, 520)
target = 'google.target.rst'
source = 'google.source.rst'
customEngineDic = dict()
Expand All @@ -514,8 +514,8 @@ def init_combobox(self):
target = engineDic[loaded_data['engine']]['target']
source = engineDic[loaded_data['engine']]['source']
if loaded_data['engine'] == 'Webbrower(Custom)':
self.frame.setFixedSize(600, 150)
self.widget.setMinimumSize(600, 630)
self.frame.setFixedSize(600, 90)
self.widget.setMinimumSize(600, 610)
elif loaded_data['engine'] in customEngineDic:
target = customEngineDic[loaded_data['engine']]['target']
source = customEngineDic[loaded_data['engine']]['source']
Expand Down Expand Up @@ -584,11 +584,11 @@ def update_progress(self, data):
self.translateBtn.setEnabled(True)
global rpy_info_dic
if len(rpy_info_dic) > 0 and self.widget.isVisible() and not self.is_waiting_translated:
self.is_waiting_translated = True
if self.radioButton.isChecked():
webbrowser.open(web_brower_export_name)
else:
open_directory_and_select_file(web_brower_export_name)
self.is_waiting_translated = True
translated_form = MyTranslatedForm()
translated_form.exec()
f = io.open('translated.txt', 'w', encoding='utf-8')
Expand Down
11 changes: 9 additions & 2 deletions src/renpy_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,14 @@ def TranslateFile(self, p, lang_target, lang_source, is_gen_bak, local_glossary,
if local_glossary is not None and len(local_glossary) > 0:
for original, replace in local_glossary.items():
target = target.replace(original, replace)
d = EncodeBrackets(target)
if is_replace_special_symbols:
d = EncodeBrackets(target)
else:
d = dict()
d['en_1'] = []
d['en_2'] = []
d['en_3'] = []
d['encoded'] = target
strip_i = target
for j in (d['en_1']):
strip_i = strip_i.replace(j, '')
Expand Down Expand Up @@ -175,7 +182,7 @@ def TranslateFile(self, p, lang_target, lang_source, is_gen_bak, local_glossary,
if is_replace_special_symbols:
translated = get_translated(trans_dic, d)
else:
translated = target
translated = trans_dic[target]
if translated is None:
translated = ''
encoded = d['encoded'].strip('"')
Expand Down
48 changes: 24 additions & 24 deletions src/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Ui_MainWindow(object):
def setupUi(self, MainWindow):
if not MainWindow.objectName():
MainWindow.setObjectName(u"MainWindow")
MainWindow.resize(1068, 572)
MainWindow.resize(1068, 612)
self.actioncopyright = QAction(MainWindow)
self.actioncopyright.setObjectName(u"actioncopyright")
self.proxySettings = QAction(MainWindow)
Expand Down Expand Up @@ -161,6 +161,17 @@ def setupUi(self, MainWindow):
self.centralwidget.setObjectName(u"centralwidget")
self.gridLayout = QGridLayout(self.centralwidget)
self.gridLayout.setObjectName(u"gridLayout")
self.verticalLayout = QVBoxLayout()
self.verticalLayout.setObjectName(u"verticalLayout")

self.gridLayout.addLayout(self.verticalLayout, 4, 0, 1, 1)

self.copyrightLabel = QLabel(self.centralwidget)
self.copyrightLabel.setObjectName(u"copyrightLabel")
self.copyrightLabel.setMaximumSize(QSize(400, 16))

self.gridLayout.addWidget(self.copyrightLabel, 4, 2, 1, 1)

self.clearLogBtn = QPushButton(self.centralwidget)
self.clearLogBtn.setObjectName(u"clearLogBtn")
sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
Expand All @@ -172,12 +183,6 @@ def setupUi(self, MainWindow):

self.gridLayout.addWidget(self.clearLogBtn, 3, 1, 1, 2)

self.copyrightLabel = QLabel(self.centralwidget)
self.copyrightLabel.setObjectName(u"copyrightLabel")
self.copyrightLabel.setMaximumSize(QSize(400, 16))

self.gridLayout.addWidget(self.copyrightLabel, 4, 2, 1, 1)

self.log_text = QTextEdit(self.centralwidget)
self.log_text.setObjectName(u"log_text")
self.log_text.setMinimumSize(QSize(100, 400))
Expand All @@ -188,10 +193,10 @@ def setupUi(self, MainWindow):

self.widget = QWidget(self.centralwidget)
self.widget.setObjectName(u"widget")
self.widget.setMinimumSize(QSize(600, 480))
self.widget.setMinimumSize(QSize(600, 520))
self.translateBtn = QPushButton(self.widget)
self.translateBtn.setObjectName(u"translateBtn")
self.translateBtn.setGeometry(QRect(0, 450, 571, 24))
self.translateBtn.setGeometry(QRect(0, 480, 571, 24))
self.selectFilesBtn = QPushButton(self.widget)
self.selectFilesBtn.setObjectName(u"selectFilesBtn")
self.selectFilesBtn.setGeometry(QRect(490, 25, 81, 81))
Expand Down Expand Up @@ -280,30 +285,25 @@ def setupUi(self, MainWindow):
self.frame = QFrame(self.widget)
self.frame.setObjectName(u"frame")
self.frame.setEnabled(True)
self.frame.setGeometry(QRect(0, 480, 600, 130))
self.frame.setMinimumSize(QSize(600, 130))
self.frame.setGeometry(QRect(0, 520, 600, 90))
self.frame.setMinimumSize(QSize(600, 90))
self.frame.setMaximumSize(QSize(0, 0))
self.frame.setFrameShape(QFrame.StyledPanel)
self.frame.setFrameShadow(QFrame.Raised)
self.replaceCheckBox = QCheckBox(self.frame)
self.replaceCheckBox.setObjectName(u"replaceCheckBox")
self.replaceCheckBox.setGeometry(QRect(20, 20, 561, 20))
self.replaceCheckBox.setChecked(True)
self.radioButton = QRadioButton(self.frame)
self.radioButton.setObjectName(u"radioButton")
self.radioButton.setGeometry(QRect(20, 60, 571, 20))
self.radioButton.setGeometry(QRect(0, 20, 571, 20))
self.radioButton.setChecked(True)
self.radioButton_2 = QRadioButton(self.frame)
self.radioButton_2.setObjectName(u"radioButton_2")
self.radioButton_2.setGeometry(QRect(20, 100, 571, 20))
self.radioButton_2.setGeometry(QRect(0, 60, 571, 20))
self.replaceCheckBox = QCheckBox(self.widget)
self.replaceCheckBox.setObjectName(u"replaceCheckBox")
self.replaceCheckBox.setGeometry(QRect(0, 450, 601, 20))
self.replaceCheckBox.setChecked(True)

self.gridLayout.addWidget(self.widget, 0, 0, 3, 1)

self.verticalLayout = QVBoxLayout()
self.verticalLayout.setObjectName(u"verticalLayout")

self.gridLayout.addLayout(self.verticalLayout, 4, 0, 1, 1)

MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QMenuBar(MainWindow)
self.menubar.setObjectName(u"menubar")
Expand Down Expand Up @@ -400,8 +400,8 @@ def retranslateUi(self, MainWindow):
self.actionofficial_extraction.setText(QCoreApplication.translate("MainWindow", u"official extraction", None))
self.actionconvert_txt_to_html.setText(QCoreApplication.translate("MainWindow", u"convert txt to html", None))
self.actionpack_game_files.setText(QCoreApplication.translate("MainWindow", u"pack game files", None))
self.clearLogBtn.setText(QCoreApplication.translate("MainWindow", u"clear log", None))
self.copyrightLabel.setText(QCoreApplication.translate("MainWindow", u"\u00a92024 Last moment,All rights reserved.", None))
self.clearLogBtn.setText(QCoreApplication.translate("MainWindow", u"clear log", None))
self.translateBtn.setText(QCoreApplication.translate("MainWindow", u"translate", None))
self.selectFilesBtn.setText(QCoreApplication.translate("MainWindow", u"...", None))
self.label_2.setText(QCoreApplication.translate("MainWindow", u"directory", None))
Expand All @@ -425,9 +425,9 @@ def retranslateUi(self, MainWindow):
self.label_16.setText(QCoreApplication.translate("MainWindow", u"(If disable, translation will continue after the previous file has been translated)", None))
self.label_14.setText(QCoreApplication.translate("MainWindow", u"filter length less than", None))
self.filterCheckBox.setText(QCoreApplication.translate("MainWindow", u"Enable filter for translate", None))
self.replaceCheckBox.setText(QCoreApplication.translate("MainWindow", u"Enable replace special symbols", None))
self.radioButton.setText(QCoreApplication.translate("MainWindow", u"Auto open untranslated contents with brower", None))
self.radioButton_2.setText(QCoreApplication.translate("MainWindow", u"Show exported html file with explorer only", None))
self.replaceCheckBox.setText(QCoreApplication.translate("MainWindow", u"Enable replace special symbols", None))
self.aboutMenu.setTitle(QCoreApplication.translate("MainWindow", u"about", None))
self.proxyMenu.setTitle(QCoreApplication.translate("MainWindow", u"proxy", None))
self.translationEngineMenu.setTitle(QCoreApplication.translate("MainWindow", u"translation engine", None))
Expand Down
Loading

0 comments on commit 9cb30b2

Please sign in to comment.