Skip to content

Commit

Permalink
<fix> fix overwrite when the untranslated contents repeat in one file
Browse files Browse the repository at this point in the history
  • Loading branch information
anonymousException committed Apr 7, 2024
1 parent 8f16028 commit 3956c79
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/renpy_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def TranslateFile(self, p, lang_target, lang_source, is_gen_bak, local_glossary,
if client is None:
return
transList = []
trans_ori_dic = dict()
trans_ori_dic = []
ret, unmatch_cnt, p = get_rpy_info(p)
if len(ret) == 0:
log_print(p + ' unable to get translated info')
Expand All @@ -110,11 +110,11 @@ def TranslateFile(self, p, lang_target, lang_source, is_gen_bak, local_glossary,
for original, replace in local_glossary.items():
target = target.replace(original, replace)
d = EncodeBrackets(target)
if isAllPunctuations(d['encoded'].strip('"')) == False:
if not isAllPunctuations(d['encoded'].strip('"')):
transList.append(d['encoded'].strip('"'))
dic['target'] = target
dic['d'] = d
trans_ori_dic[d['encoded'].strip('"')] = dic
trans_ori_dic.append((dic, d['encoded'].strip('"')))

if client.__class__.__name__ == 'Translate' and local_glossary is not None and len(local_glossary) > 0:
fmt = 'html'
Expand All @@ -131,14 +131,13 @@ def TranslateFile(self, p, lang_target, lang_source, is_gen_bak, local_glossary,
f = io.open(p + '.bak', 'w', encoding='utf-8')
f.writelines(_read_lines)
f.close()
for trans_item in transList:
ori_dic = trans_ori_dic[trans_item]
line = ori_dic['line'] - 1
ori_line = ori_dic['ori_line'] - 1
original = ori_dic['original']
current = ori_dic['current']
target = ori_dic['target']
d = ori_dic['d']
for dic, trans_key in trans_ori_dic:
line = dic['line'] - 1
ori_line = dic['ori_line'] - 1
original = dic['original']
current = dic['current']
target = dic['target']
d = dic['d']
translated = get_translated(trans_dic, d)
if translated is None:
translated = ''
Expand All @@ -159,7 +158,6 @@ def TranslateFile(self, p, lang_target, lang_source, is_gen_bak, local_glossary,
'#').lstrip()
if _read_lines[line].startswith(' old '):
_read_lines[line] = _read_lines[line].replace(' old ', ' new ', 1)

f = io.open(p, 'w', encoding='utf-8')
f.writelines(_read_lines)
f.close()
Expand Down

0 comments on commit 3956c79

Please sign in to comment.