Add comments for who is speaking

This commit is contained in:
HackerNCoder 2022-08-23 18:27:45 +02:00
parent ff5ff5f1a0
commit 09158f0510
2 changed files with 18 additions and 4 deletions

View file

@ -91,6 +91,16 @@ def extract_dialog_string(dialog_line):
return res[1]
return res[0] # (what)
def extract_dialog_pers(line):
pos = 4
res = []
while pos < len(line):
if line[pos] == "\"":
res.append({'pers': line[4:pos-1]})
return res[0]
pos += 1
return {'pers': None}
def extract_base_string(dialog_line):
res = extract_dqstrings(dialog_line)
if len(res) == 0:
@ -99,7 +109,7 @@ def extract_base_string(dialog_line):
def parse_next_block(lines):
ret = []
block_string = {'id':None, 'source':None, 'text':None, 'translation':None}
block_string = {'id':None, 'source':None, 'pers':None, 'text':None, 'translation':None}
while len(lines) > 0:
line = lines.pop()
if is_empty(line):
@ -122,7 +132,7 @@ def parse_next_block(lines):
break
elif block_string['id'] == 'strings':
# basic strings block
string = {'id':None, 'source':None, 'text':None, 'translation':None}
string = {'id':None, 'source':None, 'pers':None, 'text':None, 'translation':None}
while len(lines) > 0:
line = lines.pop()
if is_empty(line):
@ -138,7 +148,7 @@ def parse_next_block(lines):
elif line.lstrip().startswith('new '):
string['translation'] = extract_base_string(line)['text']
ret.append(string)
string = {'id':None, 'source':None, 'text':None, 'translation':None}
string = {'id':None, 'source':None, 'pers':None,'text':None, 'translation':None}
else:
pass
break
@ -156,6 +166,8 @@ def parse_next_block(lines):
# untranslated original
continue
else:
p = extract_dialog_pers(line)
block_string['pers'] = p['pers']
# dialog body
s = extract_dialog_string(line)
if s is None:

View file

@ -62,7 +62,7 @@ def tl2pot(projectpath, outfile='game.pot'):
# sort primarily by string location (not by .rpy filename) because
# Ren'Py inserts engine strings in game/tl/xxx/common.rpy
strings.sort(key=lambda s: (s['source'].split(':')[0], int(s['source'].split(':')[1])))
occurrences = {}
for s in strings:
occurrences[s['text']] = occurrences.get(s['text'], 0) + 1
@ -76,6 +76,8 @@ msgstr ""
""")
for s in strings:
if s['pers'] != None and s['pers'] != '':
out.write(u'# Speaker: ' + s['pers'] + u'\n')
out.write(u'#: ' + s['source'] + u'\n')
if occurrences[s['text']] > 1:
out.write(u'msgctxt "' + (s['id'] or s['source']) + u'"\n')