Skip to content

Commit

Permalink
<feature> improve extraction and support extract _p format (multi-lines)
Browse files Browse the repository at this point in the history
update version to v2.2.4
  • Loading branch information
anonymousException committed Apr 26, 2024
1 parent 9e37eb1 commit fd6440a
Show file tree
Hide file tree
Showing 31 changed files with 69 additions and 42 deletions.
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.
40 changes: 30 additions & 10 deletions src/renpy_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ 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)
global_e = global_e | ret_e

except Exception as e:
Expand All @@ -77,7 +77,7 @@ def ExtractFromFile(p, is_open_filter, filter_length):
# print(_read)
_read_line = _read.split('\n')
is_in_condition_switch = False
for line_content in _read_line:
for index, line_content in enumerate(_read_line):
if 'ConditionSwitch(' in line_content:
is_in_condition_switch = True
continue
Expand All @@ -90,16 +90,29 @@ def ExtractFromFile(p, is_open_filter, filter_length):
cmp_line_content = remove_upprintable_chars(line_content.strip())
if cmp_line_content.startswith('#') or len(line_content.strip()) == 0:
continue

if '_p("""' in line_content:
position = line_content.find('_p("""')
p_content = line_content[position:] + '\n'
for idx in range(index + 1, len(_read_line)):
content = _read_line[idx]
p_content = p_content + content + '\n'
if content.endswith('""")'):
p_content = p_content.rstrip('\n')
break
#log_print(p_content)
e.add(p_content)

if (is_open_filter):
if cmp_line_content.startswith('label '):
continue
if cmp_line_content.startswith('define '):
continue
# if(line_content.strip().startswith('default ')):
# continue
if line_content.strip().startswith('default '):
continue
# log_print(line_content)

suffix_list = ['.ogg', '.webp', '.png', '.ttf', '.otf', '.webm', '.svg', '.gif', '.jpg', '.wav',
'.mp3']
'.mp3','.rpyc','.rpy','.db']
is_add = False
d = EncodeBracketContent(line_content, '"', '"')
if 'oriList' in d.keys() and len(d['oriList']) > 0:
for i in d['oriList']:
Expand Down Expand Up @@ -138,8 +151,12 @@ def ExtractFromFile(p, is_open_filter, filter_length):
# log_print(len(strip_i),i)
continue
e.add(i)
is_add = True
else:
e.add(i)
is_add = True
if is_add:
continue
d = EncodeBracketContent(line_content, "'", "'")
if 'oriList' in d.keys() and len(d['oriList']) > 0:
for i in d['oriList']:
Expand Down Expand Up @@ -220,7 +237,8 @@ def GetExtractedSet(p):
lines = f.readlines()
f.close()
for j in both:
j = '"' + j + '"'
if not j.startswith('_p("""') and not j.endswith('""")'):
j = '"' + j + '"'
for index, line in enumerate(lines):
if line.startswith(' old ' + j):
lines[index] = '\n'
Expand Down Expand Up @@ -277,7 +295,8 @@ def WriteExtracted(p, extractedSet, is_open_filter, filter_length, is_gen_empty)
head = head + 'new ' + timestamp + '\n\n'
f.write(head)
for j in eDiff:
j = '"' + j + '"'
if not j.startswith('_p("""') and not j.endswith('""")'):
j = '"' + j + '"'
if not is_gen_empty:
writeData = ' old ' + j + '\n new ' + j + '\n'
else:
Expand Down Expand Up @@ -346,7 +365,8 @@ def ExtractWriteFile(p, tl_name, is_open_filter, filter_length, is_gen_empty, gl
for j in eDiff:
if j in global_e:
continue
j = '"' + j + '"'
if not j.startswith('_p("""') and not j.endswith('""")'):
j = '"' + j + '"'
if not is_gen_empty:
writeData = ' old ' + j + '\n new ' + j + '\n'
else:
Expand Down
13 changes: 10 additions & 3 deletions src/renpy_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,21 +333,28 @@ def get_rpy_info(p):
_read_line = _read.split('\n')
isLastFiltered = False
isNeedSkip = False
is_p = False
isVoice = False
unmatch_cnt = 0
for line_index, line_content in enumerate(_read_line):
if (line_content.startswith('translate ')):
if line_content.startswith('translate '):
isNeedSkip = False
split_s = line_content.split(' ')
if (len(split_s) > 2):
target = split_s[2].strip('\n')
if (target == 'python:' or target == 'style'):
isNeedSkip = True
continue
if (isNeedSkip):
if line_content.strip().startswith('old _p("""'):
is_p = True
if is_p:
if line_content.endswith('""")'):
is_p = False
continue
if isNeedSkip:
continue
isNeedSkip = False
if (line_content.strip().startswith('#') or line_content.strip().startswith('old ')):
if line_content.strip().startswith('#') or line_content.strip().startswith('old '):
isLastFiltered = True
continue
if (isLastFiltered):
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.3</source>
<translation>الإصدار2.2.3</translation>
<source>Version 2.2.4</source>
<translation>الإصدار2.2.4</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.3</source>
<translation>সংস্করণ 2.2.3</translation>
<source>Version 2.2.4</source>
<translation>সংস্করণ 2.2.4</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.3</source>
<translation>版本 2.2.3</translation>
<source>Version 2.2.4</source>
<translation>版本 2.2.4</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.3</source>
<source>Version 2.2.4</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.3</source>
<translation>Version 2.2.3</translation>
<source>Version 2.2.4</source>
<translation>Version 2.2.4</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.3</source>
<translation>Version 2.2.3</translation>
<source>Version 2.2.4</source>
<translation>Version 2.2.4</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.3</source>
<translation>संस्करण 2.2.3</translation>
<source>Version 2.2.4</source>
<translation>संस्करण 2.2.4</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.3</source>
<translation>バージョン2.2.3</translation>
<source>Version 2.2.4</source>
<translation>バージョン2.2.4</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.3</source>
<translation>버전 2.2.3</translation>
<source>Version 2.2.4</source>
<translation>버전 2.2.4</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.3</source>
<translation>Versão 2.2.3</translation>
<source>Version 2.2.4</source>
<translation>Versão 2.2.4</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.3</source>
<translation>Версия 2.2.3</translation>
<source>Version 2.2.4</source>
<translation>Версия 2.2.4</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.3</source>
<translation>Versión 2.2.3</translation>
<source>Version 2.2.4</source>
<translation>Versión 2.2.4</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.3</source>
<translation>Sürüm 2.2.3</translation>
<source>Version 2.2.4</source>
<translation>Sürüm 2.2.4</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.3</source>
<translation>ورژن 2.2.3</translation>
<source>Version 2.2.4</source>
<translation>ورژن 2.2.4</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.3", None))
self.versionLabel.setText(QCoreApplication.translate("MainWindow", u"Version 2.2.4", 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.3</string>
<string>Version 2.2.4</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit fd6440a

Please sign in to comment.