Skip to content

Commit

Permalink
<feature> Support skip extract contents with underline and improve fo…
Browse files Browse the repository at this point in the history
…nt style template

update version to v2.3.0
  • Loading branch information
anonymousException committed May 28, 2024
1 parent 1848ab6 commit 955f540
Show file tree
Hide file tree
Showing 37 changed files with 408 additions and 220 deletions.
13 changes: 9 additions & 4 deletions src/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class Ui_ExtractionDialog(object):
def setupUi(self, ExtractionDialog):
if not ExtractionDialog.objectName():
ExtractionDialog.setObjectName(u"ExtractionDialog")
ExtractionDialog.resize(652, 452)
ExtractionDialog.resize(652, 472)
self.widget_2 = QWidget(ExtractionDialog)
self.widget_2.setObjectName(u"widget_2")
self.widget_2.setGeometry(QRect(20, 10, 600, 430))
self.widget_2.setGeometry(QRect(20, 10, 600, 451))
self.widget_2.setMinimumSize(QSize(600, 430))
self.selectFilesText_2 = QTextEdit(self.widget_2)
self.selectFilesText_2.setObjectName(u"selectFilesText_2")
Expand Down Expand Up @@ -56,7 +56,7 @@ def setupUi(self, ExtractionDialog):
self.selectDirText_2.setGeometry(QRect(80, 170, 411, 61))
self.extractBtn = QPushButton(self.widget_2)
self.extractBtn.setObjectName(u"extractBtn")
self.extractBtn.setGeometry(QRect(84, 390, 411, 24))
self.extractBtn.setGeometry(QRect(84, 420, 411, 24))
self.label_8 = QLabel(self.widget_2)
self.label_8.setObjectName(u"label_8")
self.label_8.setGeometry(QRect(0, 250, 71, 31))
Expand Down Expand Up @@ -86,7 +86,11 @@ def setupUi(self, ExtractionDialog):
self.filterLengthLineEdit.setGeometry(QRect(470, 330, 31, 20))
self.emptyCheckBox = QCheckBox(self.widget_2)
self.emptyCheckBox.setObjectName(u"emptyCheckBox")
self.emptyCheckBox.setGeometry(QRect(0, 360, 501, 20))
self.emptyCheckBox.setGeometry(QRect(0, 390, 601, 20))
self.underlineCheckBox = QCheckBox(self.widget_2)
self.underlineCheckBox.setObjectName(u"underlineCheckBox")
self.underlineCheckBox.setGeometry(QRect(0, 360, 601, 20))
self.underlineCheckBox.setChecked(True)

self.retranslateUi(ExtractionDialog)

Expand Down Expand Up @@ -117,5 +121,6 @@ def retranslateUi(self, ExtractionDialog):
self.filterCheckBox.setText(QCoreApplication.translate("ExtractionDialog", u"Enable filter for extract", None))
self.label_14.setText(QCoreApplication.translate("ExtractionDialog", u"filter length less than", None))
self.emptyCheckBox.setText(QCoreApplication.translate("ExtractionDialog", u"Generate empty strings instead of original", None))
self.underlineCheckBox.setText(QCoreApplication.translate("ExtractionDialog", u"Skip extract the contents which include underline", None))
# retranslateUi

26 changes: 21 additions & 5 deletions src/extraction.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>652</width>
<height>452</height>
<height>472</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -19,7 +19,7 @@
<x>20</x>
<y>10</y>
<width>600</width>
<height>430</height>
<height>451</height>
</rect>
</property>
<property name="minimumSize">
Expand Down Expand Up @@ -137,7 +137,7 @@
<property name="geometry">
<rect>
<x>84</x>
<y>390</y>
<y>420</y>
<width>411</width>
<height>24</height>
</rect>
Expand Down Expand Up @@ -263,15 +263,31 @@
<property name="geometry">
<rect>
<x>0</x>
<y>360</y>
<width>501</width>
<y>390</y>
<width>601</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Generate empty strings instead of original</string>
</property>
</widget>
<widget class="QCheckBox" name="underlineCheckBox">
<property name="geometry">
<rect>
<x>0</x>
<y>360</y>
<width>601</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Skip extract the contents which include underline</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</widget>
</widget>
<resources/>
Expand Down
6 changes: 3 additions & 3 deletions src/extraction_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def extract(self):
t = extractThread(threadID=cnt, p=i, tl_name=tl_name, dirs=None, tl_dir=None,
is_open_filter=self.filterCheckBox.isChecked(),
filter_length=int(self.filterLengthLineEdit.text()),
is_gen_empty=self.emptyCheckBox.isChecked())
is_gen_empty=self.emptyCheckBox.isChecked(), is_skip_underline=self.underlineCheckBox.isChecked())
extract_threads.append(t)
cnt = cnt + 1
select_dirs = self.selectDirsText.toPlainText().split('\n')
Expand All @@ -111,7 +111,7 @@ def extract(self):
t = extractThread(threadID=cnt, p=None, tl_name=tl_name, dirs=_dirs, tl_dir=None,
is_open_filter=self.filterCheckBox.isChecked(),
filter_length=int(self.filterLengthLineEdit.text()),
is_gen_empty=self.emptyCheckBox.isChecked())
is_gen_empty=self.emptyCheckBox.isChecked(), is_skip_underline=self.underlineCheckBox.isChecked())
extract_threads.append(t)
cnt = cnt + 1
select_dir = self.selectDirText_2.toPlainText()
Expand All @@ -126,7 +126,7 @@ def extract(self):
t = extractThread(threadID=cnt, p=None, tl_name=tl_name, dirs=None, tl_dir=select_dir,
is_open_filter=self.filterCheckBox.isChecked(),
filter_length=int(self.filterLengthLineEdit.text()),
is_gen_empty=self.emptyCheckBox.isChecked())
is_gen_empty=self.emptyCheckBox.isChecked(), is_skip_underline=self.underlineCheckBox.isChecked())
extract_threads.append(t)
cnt = cnt + 1
if len(extract_threads) > 0:
Expand Down
1 change: 1 addition & 0 deletions src/font_style_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ translate {tl_name} python:
def change_font(font_path):
gui.text_font = gui.interface_text_font = gui.button_text_font = gui.choice_button_text_font = FontGroup().add(font_path, 0x5187, 0x5187).add(font_path, 0x5463, 0x5463).add(font_path, 0x5c44, 0x5c44).add(font_path, 0x5c4c, 0x5c4c).add(font_path, 0x808f, 0x808f).add(font_path, 0x6294, 0x6294).add(font_path, 0x2014, 0x201F).add(font_path, 0x2E80, 0xffff).add(font_path, 0x0000, 0xffff)
gui.name_text_font = font_path
style.default.font = font_path
gui.headline_text_font = FontGroup().add(font_path, 0x2E80, 0xffff).add(font_path, 0x0000, 0xffff)
font_path = "{font_path}"
change_font(font_path)
13 changes: 9 additions & 4 deletions src/one_key_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def setupUi(self, OneKeyTranslateDialog):
self.label_10.setGeometry(QRect(30, 280, 41, 31))
self.localGlossaryCheckBox = QCheckBox(OneKeyTranslateDialog)
self.localGlossaryCheckBox.setObjectName(u"localGlossaryCheckBox")
self.localGlossaryCheckBox.setGeometry(QRect(30, 380, 571, 20))
self.localGlossaryCheckBox.setGeometry(QRect(30, 370, 571, 20))
self.selectFontBtn = QPushButton(OneKeyTranslateDialog)
self.selectFontBtn.setObjectName(u"selectFontBtn")
self.selectFontBtn.setGeometry(QRect(520, 490, 81, 91))
Expand Down Expand Up @@ -95,16 +95,16 @@ def setupUi(self, OneKeyTranslateDialog):
self.translateCheckBox.setChecked(True)
self.filterCheckBox = QCheckBox(OneKeyTranslateDialog)
self.filterCheckBox.setObjectName(u"filterCheckBox")
self.filterCheckBox.setGeometry(QRect(30, 420, 261, 20))
self.filterCheckBox.setGeometry(QRect(30, 400, 261, 20))
self.filterCheckBox.setChecked(True)
self.filterLengthLineEdit = QLineEdit(OneKeyTranslateDialog)
self.filterLengthLineEdit.setObjectName(u"filterLengthLineEdit")
self.filterLengthLineEdit.setGeometry(QRect(500, 420, 101, 20))
self.filterLengthLineEdit.setGeometry(QRect(500, 400, 101, 20))
self.filterLengthLineEdit.setText(u"8")
self.filterLengthLineEdit.setAlignment(Qt.AlignCenter)
self.label_14 = QLabel(OneKeyTranslateDialog)
self.label_14.setObjectName(u"label_14")
self.label_14.setGeometry(QRect(290, 422, 201, 16))
self.label_14.setGeometry(QRect(290, 402, 201, 16))
self.label_14.setAlignment(Qt.AlignCenter)
self.startButton = QPushButton(OneKeyTranslateDialog)
self.startButton.setObjectName(u"startButton")
Expand All @@ -126,6 +126,10 @@ def setupUi(self, OneKeyTranslateDialog):
self.label_15.setObjectName(u"label_15")
self.label_15.setGeometry(QRect(290, 460, 201, 16))
self.label_15.setAlignment(Qt.AlignCenter)
self.underlineCheckBox = QCheckBox(OneKeyTranslateDialog)
self.underlineCheckBox.setObjectName(u"underlineCheckBox")
self.underlineCheckBox.setGeometry(QRect(30, 430, 581, 20))
self.underlineCheckBox.setChecked(True)

self.retranslateUi(OneKeyTranslateDialog)

Expand Down Expand Up @@ -161,5 +165,6 @@ def retranslateUi(self, OneKeyTranslateDialog):
self.officialExtractionCheckBox.setText(QCoreApplication.translate("OneKeyTranslateDialog", u"Official Extraction", None))
self.filterCheckBox_2.setText(QCoreApplication.translate("OneKeyTranslateDialog", u"Enable filter for translate", None))
self.label_15.setText(QCoreApplication.translate("OneKeyTranslateDialog", u"filter length less than", None))
self.underlineCheckBox.setText(QCoreApplication.translate("OneKeyTranslateDialog", u"Skip extract the contents which include underline", None))
# retranslateUi

24 changes: 20 additions & 4 deletions src/one_key_translate.ui
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
<property name="geometry">
<rect>
<x>30</x>
<y>380</y>
<y>370</y>
<width>571</width>
<height>20</height>
</rect>
Expand Down Expand Up @@ -301,7 +301,7 @@
<property name="geometry">
<rect>
<x>30</x>
<y>420</y>
<y>400</y>
<width>261</width>
<height>20</height>
</rect>
Expand All @@ -317,7 +317,7 @@
<property name="geometry">
<rect>
<x>500</x>
<y>420</y>
<y>400</y>
<width>101</width>
<height>20</height>
</rect>
Expand All @@ -333,7 +333,7 @@
<property name="geometry">
<rect>
<x>290</x>
<y>422</y>
<y>402</y>
<width>201</width>
<height>16</height>
</rect>
Expand Down Expand Up @@ -422,6 +422,22 @@
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QCheckBox" name="underlineCheckBox">
<property name="geometry">
<rect>
<x>30</x>
<y>430</y>
<width>581</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Skip extract the contents which include underline</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</widget>
<resources/>
<connections/>
Expand Down
2 changes: 1 addition & 1 deletion src/one_key_translate_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def extract(self):
t = renpy_extract.extractThread(threadID=0, p=None, tl_name=tl_name, dirs=None, tl_dir=select_dir,
is_open_filter=self.filterCheckBox.isChecked(),
filter_length=int(self.filterLengthLineEdit.text()),
is_gen_empty=False)
is_gen_empty=False, is_skip_underline=self.underlineCheckBox.isChecked())
renpy_extract.extract_threads.append(t)

if len(renpy_extract.extract_threads) > 0:
Expand Down
Binary file modified src/qm/arabic.qm
Binary file not shown.
Binary file modified src/qm/bengali.qm
Binary file not shown.
Binary file modified src/qm/chinese.qm
Binary file not shown.
Binary file modified src/qm/french.qm
Binary file not shown.
Binary file modified src/qm/german.qm
Binary file not shown.
Binary file modified src/qm/hindi.qm
Binary file not shown.
Binary file modified src/qm/japanese.qm
Binary file not shown.
Binary file modified src/qm/korean.qm
Binary file not shown.
Binary file modified src/qm/portuguese.qm
Binary file not shown.
Binary file modified src/qm/russian.qm
Binary file not shown.
Binary file modified src/qm/spanish.qm
Binary file not shown.
Binary file modified src/qm/turkish.qm
Binary file not shown.
Binary file modified src/qm/urdu.qm
Binary file not shown.
37 changes: 21 additions & 16 deletions src/renpy_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


class extractThread(threading.Thread):
def __init__(self, threadID, p, tl_name, dirs, tl_dir, is_open_filter, filter_length, is_gen_empty):
def __init__(self, threadID, p, tl_name, dirs, tl_dir, is_open_filter, filter_length, is_gen_empty, is_skip_underline):
threading.Thread.__init__(self)
self.threadID = threadID
self.p = p
Expand All @@ -31,6 +31,7 @@ def __init__(self, threadID, p, tl_name, dirs, tl_dir, is_open_filter, filter_le
self.is_open_filter = is_open_filter
self.filter_length = filter_length
self.is_gen_empty = is_gen_empty
self.is_skip_underline = is_skip_underline

def run(self):
try:
Expand All @@ -41,13 +42,13 @@ def run(self):
ori_tl = os.path.basename(self.tl_dir)
self.tl_dir = self.tl_dir[:-len(ori_tl)] + self.tl_name
log_print(self.tl_dir + ' begin extract!')
ExtractAllFilesInDir(self.tl_dir, self.is_open_filter, self.filter_length, self.is_gen_empty)
ExtractAllFilesInDir(self.tl_dir, self.is_open_filter, self.filter_length, self.is_gen_empty, self.is_skip_underline)
else:
if self.p is not None:
self.p = self.p.replace('\\', '/')
log_print(self.p + ' begin extract!')
ExtractWriteFile(self.p, self.tl_name, self.is_open_filter, self.filter_length, self.is_gen_empty,
set())
set(), self.is_skip_underline)
if self.dirs is not None:
global_e = set()
for _dir in self.dirs:
Expand All @@ -61,15 +62,15 @@ def run(self):
if not file_name.endswith("rpy"):
continue
ret_e = ExtractWriteFile(i, self.tl_name, self.is_open_filter, self.filter_length,
self.is_gen_empty, global_e)
self.is_gen_empty, global_e, self.is_skip_underline)
global_e = global_e | ret_e

except Exception as e:
msg = traceback.format_exc()
log_print(msg)


def ExtractFromFile(p, is_open_filter, filter_length):
def ExtractFromFile(p, is_open_filter, filter_length, is_skip_underline):
e = set()
f = io.open(p, 'r+', encoding='utf-8')
_read = f.read()
Expand Down Expand Up @@ -142,6 +143,8 @@ def ExtractFromFile(p, is_open_filter, filter_length):
skip = False
if cmp_i.startswith('#'):
skip = True
if is_skip_underline and strip_i.find('_') > -1:
skip = True
# if not line_content.strip().startswith('text ') or line_content.strip().find(i) != 5:
# skip = True
for suffix in suffix_list:
Expand Down Expand Up @@ -186,6 +189,8 @@ def ExtractFromFile(p, is_open_filter, filter_length):
skip = False
if cmp_i.startswith('#'):
skip = True
if is_skip_underline and _strip_i.find('_') > -1:
skip = True
# if not line_content.strip().startswith('text ') or line_content.strip().find(i) != 5:
# skip = True
for suffix in suffix_list:
Expand Down Expand Up @@ -229,7 +234,7 @@ def CreateEmptyFileIfNotExsit(p):
open(target, 'w').close()


def GetExtractedSet(p):
def GetExtractedSet(p, is_skip_underline):
if (p[len(p) - 1] != '/' and p[len(p) - 1] != '\\'):
p = p + '/'
e = set()
Expand All @@ -239,7 +244,7 @@ def GetExtractedSet(p):
i = os.path.join(path, file_name)
if (file_name.endswith("rpy") == False):
continue
extracted = ExtractFromFile(i, False, 9999)
extracted = ExtractFromFile(i, False, 9999, is_skip_underline)
both = e & extracted
if len(both) > 0:
f = io.open(i, 'r', encoding='utf-8')
Expand All @@ -260,7 +265,7 @@ def GetExtractedSet(p):
return e


def WriteExtracted(p, extractedSet, is_open_filter, filter_length, is_gen_empty):
def WriteExtracted(p, extractedSet, is_open_filter, filter_length, is_gen_empty, is_skip_underline):
if (p[len(p) - 1] != '/' and p[len(p) - 1] != '\\'):
p = p + '/'
index = p.rfind('tl\\')
Expand All @@ -287,7 +292,7 @@ def WriteExtracted(p, extractedSet, is_open_filter, filter_length, is_gen_empty)
log_print(target + " not exists skip!")
continue

e = ExtractFromFile(target, is_open_filter, filter_length)
e = ExtractFromFile(target, is_open_filter, filter_length, is_skip_underline)
eDiff = e - extractedSet
if len(eDiff) > 0:
f = io.open(i, 'a+', encoding='utf-8')
Expand Down Expand Up @@ -337,7 +342,7 @@ def GetHeaderPath(p):
return dic


def ExtractWriteFile(p, tl_name, is_open_filter, filter_length, is_gen_empty, global_e):
def ExtractWriteFile(p, tl_name, is_open_filter, filter_length, is_gen_empty, global_e, is_skip_underline):
dic = GetHeaderPath(p)
header = dic['header']
if (header == ''):
Expand All @@ -354,8 +359,8 @@ def ExtractWriteFile(p, tl_name, is_open_filter, filter_length, is_gen_empty, gl
pass
if (os.path.isfile(target) == False):
open(target, 'w').close()
e = ExtractFromFile(p, is_open_filter, filter_length)
extractedSet = ExtractFromFile(target, False, 9999)
e = ExtractFromFile(p, is_open_filter, filter_length, is_skip_underline)
extractedSet = ExtractFromFile(target, False, 9999, is_skip_underline)
eDiff = e - extractedSet
if len(eDiff) > 0:
f = io.open(target, 'a+', encoding='utf-8')
Expand Down Expand Up @@ -388,8 +393,8 @@ def ExtractWriteFile(p, tl_name, is_open_filter, filter_length, is_gen_empty, gl
return global_e


def ExtractAllFilesInDir(dirName, is_open_filter, filter_length, is_gen_empty):
def ExtractAllFilesInDir(dirName, is_open_filter, filter_length, is_gen_empty, is_skip_underline):
CreateEmptyFileIfNotExsit(dirName)
ret = GetExtractedSet(dirName)
WriteExtracted(dirName, ret, is_open_filter, filter_length, is_gen_empty)
ret = GetExtractedSet(dirName)
ret = GetExtractedSet(dirName, is_skip_underline)
WriteExtracted(dirName, ret, is_open_filter, filter_length, is_gen_empty, is_skip_underline)
ret = GetExtractedSet(dirName, is_skip_underline)
Loading

0 comments on commit 955f540

Please sign in to comment.