Skip to content

Commit

Permalink
<feature> fix duplicate extraction when extract from directory(s)
Browse files Browse the repository at this point in the history
update version to v2.2.2
  • Loading branch information
anonymousException committed Apr 23, 2024
1 parent 1fff8ab commit 4f3ff33
Show file tree
Hide file tree
Showing 32 changed files with 59 additions and 54 deletions.
19 changes: 10 additions & 9 deletions src/extraction_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,28 +91,29 @@ def extract(self):
if len(tl_name) == 0:
log_print('tl name is empty skip extract file(s)')
continue
t = extractThread(threadID=cnt, p=i, tl_name=tl_name, dir=None, tl_dir=None,
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())
extract_threads.append(t)
cnt = cnt + 1
select_dirs = self.selectDirsText.toPlainText().split('\n')
_dirs = []
for i in select_dirs:
i = i.replace('file:///', '')
if len(i) > 0:
tl_name = self.tlNameText.toPlainText()
if len(tl_name) == 0:
log_print('tl name is empty skip extract directory(s)')
continue
t = extractThread(threadID=cnt, p=None, tl_name=tl_name, dir=i, tl_dir=None,
_dirs.append(i)
if len(_dirs) > 0:
tl_name = self.tlNameText.toPlainText()
if len(tl_name) == 0:
log_print('tl name is empty skip extract directory(s)')
else:
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())
extract_threads.append(t)
cnt = cnt + 1
pass

select_dir = self.selectDirText_2.toPlainText()
if len(select_dir) > 0:
select_dir = select_dir.replace('file:///', '')
Expand All @@ -122,7 +123,7 @@ def extract(self):
else:
if select_dir[len(select_dir) - 1] != '/' and select_dir[len(select_dir) - 1] != '\\':
select_dir = select_dir + '/'
t = extractThread(threadID=cnt, p=None, tl_name=tl_name, dir=None, tl_dir=select_dir,
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())
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 @@ -258,7 +258,7 @@ def extract(self):
else:
if select_dir[len(select_dir) - 1] != '/' and select_dir[len(select_dir) - 1] != '\\':
select_dir = select_dir + '/'
t = renpy_extract.extractThread(threadID=0, p=None, tl_name=tl_name, dir=None, tl_dir=select_dir,
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)
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.
34 changes: 19 additions & 15 deletions src/renpy_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@


class extractThread(threading.Thread):
def __init__(self, threadID, p, tl_name, dir, 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):
threading.Thread.__init__(self)
self.threadID = threadID
self.p = p
self.tl_name = tl_name
self.dir = dir
self.dirs = dirs
self.tl_dir = tl_dir
self.is_open_filter = is_open_filter
self.filter_length = filter_length
Expand All @@ -47,17 +47,19 @@ def run(self):
log_print(self.p + ' begin extract!')
ExtractWriteFile(self.p, self.tl_name, self.is_open_filter, self.filter_length, self.is_gen_empty,
set())
if self.dir is not None:
log_print(self.dir + ' begin extract!')
paths = os.walk(self.dir, topdown=False)
if self.dirs is not None:
global_e = set()
for path, dir_lst, file_lst in paths:
for file_name in file_lst:
i = os.path.join(path, file_name)
if not file_name.endswith("rpy"):
continue
global_e = ExtractWriteFile(i, self.tl_name, self.is_open_filter, self.filter_length,
self.is_gen_empty, global_e)
for _dir in self.dirs:
log_print(_dir + ' begin extract!')
paths = os.walk(_dir, topdown=False)
for path, dir_lst, file_lst in paths:
for file_name in file_lst:
i = os.path.join(path, file_name)
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)
global_e = global_e | ret_e

except Exception as e:
msg = traceback.format_exc()
Expand Down Expand Up @@ -322,10 +324,9 @@ def ExtractWriteFile(p, tl_name, is_open_filter, filter_length, is_gen_empty, gl
if (os.path.isfile(target) == False):
open(target, 'w').close()
e = ExtractFromFile(p, is_open_filter, filter_length)
global_e = global_e | e
extractedSet = ExtractFromFile(target, False, 9999)
eDiff = global_e - extractedSet
if (len(eDiff) > 0):
eDiff = e - extractedSet
if len(eDiff) > 0:
f = io.open(target, 'a+', encoding='utf-8')
f.write('\ntranslate ' + tl_name + ' strings:\n')
lock.acquire()
Expand All @@ -340,13 +341,16 @@ def ExtractWriteFile(p, tl_name, is_open_filter, filter_length, is_gen_empty, gl
head = head + 'new ' + timestamp + '\n\n'
f.write(head)
for j in eDiff:
if j in global_e:
continue
j = '"' + j + '"'
if not is_gen_empty:
writeData = ' old ' + j + '\n new ' + j + '\n'
else:
writeData = ' old ' + j + '\n new ' + '""' + '\n'
f.write(writeData + '\n')
f.close()
global_e = global_e | e
global_e = global_e | extractedSet
log_print(target + ' extracted success!')
return global_e
Expand Down
4 changes: 2 additions & 2 deletions src/ts/arabic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.1</source>
<translation>الإصدار2.2.1</translation>
<source>Version 2.2.2</source>
<translation>الإصدار2.2.2</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/bengali.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.1</source>
<translation>সংস্করণ 2.2.1</translation>
<source>Version 2.2.2</source>
<translation>সংস্করণ 2.2.2</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/chinese.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1178,8 +1178,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.1</source>
<translation>版本 2.2.1</translation>
<source>Version 2.2.2</source>
<translation>版本 2.2.2</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
2 changes: 1 addition & 1 deletion src/ts/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.1</source>
<source>Version 2.2.2</source>
<translation type="unfinished"></translation>
</message>
<message>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/french.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.1</source>
<translation>Version 2.2.1</translation>
<source>Version 2.2.2</source>
<translation>Version 2.2.2</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/german.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1288,8 +1288,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.1</source>
<translation>Version 2.2.1</translation>
<source>Version 2.2.2</source>
<translation>Version 2.2.2</translation>
</message>
<message>
<location filename="../ui.ui" line="391"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/hindi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.1</source>
<translation>संस्करण 2.2.1</translation>
<source>Version 2.2.2</source>
<translation>संस्करण 2.2.2</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/japanese.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1174,8 +1174,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.1</source>
<translation>バージョン2.2.1</translation>
<source>Version 2.2.2</source>
<translation>バージョン2.2.2</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/korean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1288,8 +1288,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.1</source>
<translation>버전 2.2.1</translation>
<source>Version 2.2.2</source>
<translation>버전 2.2.2</translation>
</message>
<message>
<location filename="../ui.ui" line="391"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/portuguese.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.1</source>
<translation>Versão 2.2.1</translation>
<source>Version 2.2.2</source>
<translation>Versão 2.2.2</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/russian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.1</source>
<translation>Версия 2.2.1</translation>
<source>Version 2.2.2</source>
<translation>Версия 2.2.2</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/spanish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.1</source>
<translation>Versión 2.2.1</translation>
<source>Version 2.2.2</source>
<translation>Versión 2.2.2</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/turkish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1265,8 +1265,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.1</source>
<translation>Sürüm 2.2.1</translation>
<source>Version 2.2.2</source>
<translation>Sürüm 2.2.2</translation>
</message>
<message>
<location filename="../ui.ui" line="391"/>
Expand Down
4 changes: 2 additions & 2 deletions src/ts/urdu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,8 @@
</message>
<message>
<location filename="../ui.ui" line="78"/>
<source>Version 2.2.1</source>
<translation>ورژن 2.2.1</translation>
<source>Version 2.2.2</source>
<translation>ورژن 2.2.2</translation>
</message>
<message>
<location filename="../ui.ui" line="113"/>
Expand Down
2 changes: 1 addition & 1 deletion src/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def retranslateUi(self, MainWindow):
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.versionLabel.setText(QCoreApplication.translate("MainWindow", u"Version 2.2.1", None))
self.versionLabel.setText(QCoreApplication.translate("MainWindow", u"Version 2.2.2", 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 Down
2 changes: 1 addition & 1 deletion src/ui.ui
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
</size>
</property>
<property name="text">
<string>Version 2.2.1</string>
<string>Version 2.2.2</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit 4f3ff33

Please sign in to comment.