-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<feature> correct error translation format after extraction by renpy …
…hint update version to v2.5.7
- Loading branch information
1 parent
a706bcc
commit 626e09c
Showing
4 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import io | ||
import os | ||
import subprocess | ||
|
||
from call_game_python import get_python_path_from_game_path, get_py_path | ||
from my_log import log_print | ||
|
||
|
||
def get_renpy_cmd(game_path): | ||
python_path = get_python_path_from_game_path(game_path) | ||
py_path = get_py_path(game_path) | ||
game_dir = os.path.dirname(game_path) | ||
command = '"' + python_path + '"' + ' -O "' + py_path + '" "' + game_dir + '" lint --error-code' | ||
return command | ||
|
||
|
||
def exec_renpy_lint(game_path): | ||
command = get_renpy_cmd(game_path) | ||
log_print(command) | ||
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, | ||
creationflags=0x08000000, text=True, encoding='utf-8') | ||
p.wait() | ||
stdout, stderr = p.communicate() | ||
return stdout, stderr | ||
|
||
|
||
def fix_translation_by_lint(game_path): | ||
stdout, stderr = exec_renpy_lint(game_path) | ||
if len(stderr) > 0: | ||
log_print(f'call renpy lint error : {stderr}') | ||
return | ||
lines = stdout.splitlines() | ||
is_fixed = False | ||
fix_list = [] | ||
for line in lines: | ||
err_file = '' | ||
err_line = -1 | ||
if line.endswith('is not terminated with a newline. (Check strings and parenthesis.)') or line.endswith('end of line expected.') or line.endswith('translate statement expects a non-empty block.'): | ||
idx = line.index(', line ') | ||
err_file = line[line.index(' ') + 1:idx].strip('"') | ||
err_line = line[idx + len(', line '): line.index(':', idx)].strip() | ||
err_line = int(err_line) - 1 | ||
if line in fix_list: | ||
continue | ||
fix_list.append(line) | ||
if line.startswith('Exception: A translation for '): | ||
idx = line.rindex('already exists at ') | ||
err_content = line[len('Exception: A translation for '):idx].rstrip().strip('"') | ||
idx = idx + len('already exists at ') | ||
err_info = line[idx:].rstrip('.').lstrip() | ||
err_file, err_line = err_info.split(':', 1) | ||
err_line = int(err_line) + 1 | ||
if err_info in fix_list: | ||
continue | ||
fix_list.append(err_info) | ||
if err_line == -1: | ||
continue | ||
err_file = os.path.dirname(game_path) + '/' + err_file | ||
if not os.path.isfile(err_file): | ||
log_print('error path : ' + err_file) | ||
f = io.open(err_file, 'r', encoding='utf-8') | ||
_lines = f.readlines() | ||
f.close() | ||
log_print('remove error line ' + str(err_line - 1) + ' in ' + err_file + ' , "' + _lines[err_line] + '"') | ||
if _lines[err_line].startswith(' old ') and _lines[err_line + 1].startswith(' new '): | ||
_lines[err_line] = '' | ||
_lines[err_line + 1] = '' | ||
if _lines[err_line - 1].lstrip().startswith('#'): | ||
_lines[err_line - 1] = '' | ||
elif _lines[err_line].startswith(' new ') and _lines[err_line - 1].startswith(' old '): | ||
_lines[err_line] = '' | ||
_lines[err_line - 1] = '' | ||
if _lines[err_line - 2].lstrip().startswith('#'): | ||
_lines[err_line - 2] = '' | ||
else: | ||
_lines[err_line] = ' ""\n' | ||
|
||
f = io.open(err_file, 'w', encoding='utf-8') | ||
f.writelines(_lines) | ||
f.close() | ||
is_fixed = True | ||
return is_fixed | ||
|
||
|
||
def fix_translation_by_lint_recursion(game_path, max_recursion_depth=512): | ||
cnt = 0 | ||
while True: | ||
if not fix_translation_by_lint(game_path): | ||
break | ||
cnt = cnt + 1 | ||
if cnt > max_recursion_depth: | ||
break | ||
|
||
|
||
#fix_translation_by_lint_recursion('F:/Games/RenPy/DemoGame-1.1-dists/DemoGame-1.1-win/DemoGame.exe') |