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
  • Loading branch information
anonymousException committed Apr 26, 2024
1 parent fd6440a commit b9917c0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
26 changes: 16 additions & 10 deletions src/renpy_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def ExtractFromFile(p, is_open_filter, filter_length):
# print(_read)
_read_line = _read.split('\n')
is_in_condition_switch = False
is_in__p = False
p_content = ''
for index, line_content in enumerate(_read_line):
if 'ConditionSwitch(' in line_content:
is_in_condition_switch = True
Expand All @@ -92,18 +94,22 @@ def ExtractFromFile(p, is_open_filter, filter_length):
continue

if '_p("""' in line_content:
is_in__p = True
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):
continue

if is_in__p:
p_content = p_content + line_content + '\n'
if line_content.endswith('""")'):
p_content = p_content.rstrip('\n')
#log_print(p_content)
e.add(p_content)
is_in__p = False
p_content = ''
continue

if is_open_filter:
if cmp_line_content.startswith('label '):
continue
if line_content.strip().startswith('default '):
Expand Down
8 changes: 7 additions & 1 deletion src/renpy_fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,14 @@ def replace_tl_folder(full_tl_path, font_name):
f = io.open(i, 'r', encoding='utf-8')
lines = f.readlines()
f.close()

is_p = False
for index, line in enumerate(lines):
if line.strip().startswith('old _p("""'):
is_p = True
if is_p:
if line.endswith('""")\n'):
is_p = False
continue
if not '{font' in line:
continue
if not line.strip().startswith('#') and not line.strip().startswith('old '):
Expand Down
14 changes: 7 additions & 7 deletions src/renpy_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,12 @@ def get_rpy_info(p):
if line_content.startswith('translate '):
isNeedSkip = False
split_s = line_content.split(' ')
if (len(split_s) > 2):
if len(split_s) > 2:
target = split_s[2].strip('\n')
if (target == 'python:' or target == 'style'):
if target == 'python:' or target == 'style':
isNeedSkip = True
continue
if line_content.strip().startswith('old _p("""'):
if line_content.strip().startswith('old _p("""') or line_content.strip().startswith('new _p("""'):
is_p = True
if is_p:
if line_content.endswith('""")'):
Expand All @@ -357,7 +357,7 @@ def get_rpy_info(p):
if line_content.strip().startswith('#') or line_content.strip().startswith('old '):
isLastFiltered = True
continue
if (isLastFiltered):
if isLastFiltered:
isLastFiltered = False
# if (_read_line[line_index - 1].strip()[4:] != _read_line[line_index].strip()[4:] and _read_line[
# line_index - 1].strip()[
Expand All @@ -370,7 +370,7 @@ def get_rpy_info(p):
if line_index > 0 and not _read_line[line_index - 1].strip().startswith('#') and not _read_line[
line_index - 1].strip().startswith('old '):
continue
if (line_content.strip().lstrip('#').strip().startswith('voice ')):
if line_content.strip().lstrip('#').strip().startswith('voice '):
isVoice = True
continue
d = EncodeBracketContent(line_content, '"', '"')
Expand All @@ -380,10 +380,10 @@ def get_rpy_info(p):
line_content = line_content[:-2] + '" "'
d = EncodeBracketContent(line_content, '"', '"')
is_empty = True
if ('oriList' in d.keys() and len(d['oriList']) > 0):
if 'oriList' in d.keys() and len(d['oriList']) > 0:
# print(d['oriList'])
for i, e in enumerate(d['oriList']):
if (isAllPunctuations(d['encoded'].strip('"')) == False):
if isAllPunctuations(d['encoded'].strip('"')) == False:
target_index = line_index - 1
if isVoice:
target_index = target_index - 1
Expand Down

0 comments on commit b9917c0

Please sign in to comment.