Get symbols from each line
This commit is contained in:
parent
8950d352ba
commit
5e7295cf72
48
src/orig.py
48
src/orig.py
|
@ -44,6 +44,49 @@ def process_sections():
|
|||
origfile.close()
|
||||
|
||||
|
||||
def get_symbols(line: str) -> list[str]:
|
||||
res = []
|
||||
|
||||
inbetween = 0
|
||||
i = 0
|
||||
while i < len(line):
|
||||
if line[i] in ['@', '/', '¥']:
|
||||
if inbetween > 0:
|
||||
res.append(line[i])
|
||||
else:
|
||||
res[-1] += line[i]
|
||||
inbetween = 0
|
||||
elif line[i:i+3] == '!sd':
|
||||
if inbetween > 0:
|
||||
res.append(line[i:i+3])
|
||||
else:
|
||||
res[-1] += line[i:i+3]
|
||||
inbetween = 0
|
||||
i += 3
|
||||
elif line[i:i+2] in ['!d', '!w', '!s']:
|
||||
x = i
|
||||
i += 2
|
||||
while i < len(line):
|
||||
if line[i].isdigit():
|
||||
i += 1
|
||||
continue
|
||||
|
||||
if inbetween > 0:
|
||||
res.append(line[x:i])
|
||||
else:
|
||||
res[-1] += line[x:i]
|
||||
inbetween = 0
|
||||
break
|
||||
elif line[i] == '!':
|
||||
raise Exception('Unhandled symbol', line)
|
||||
else:
|
||||
inbetween += 1
|
||||
|
||||
i += 1
|
||||
|
||||
return res
|
||||
|
||||
|
||||
# Given a set of translation files, the original file and the output file
|
||||
# replace the japanese lines with the translated ones in a given section.
|
||||
def write_translated(outfile, origfile, translation_file_paths):
|
||||
|
@ -52,6 +95,7 @@ def write_translated(outfile, origfile, translation_file_paths):
|
|||
structure = parser.parse_to_structure(transfilepath)
|
||||
|
||||
for i, line in enumerate(origfile):
|
||||
# Check if the current line is a dialogue line or not
|
||||
found = False
|
||||
for start, end in japanese_ranges:
|
||||
if start <= ord(line[0]) <= end:
|
||||
|
@ -65,6 +109,10 @@ def write_translated(outfile, origfile, translation_file_paths):
|
|||
# equivalent to the given original line.
|
||||
amount = line.count("@") + line.count("¥") + line.count('/')
|
||||
|
||||
symbols = get_symbols(line)
|
||||
print(symbols, line, end='')
|
||||
continue
|
||||
|
||||
outfile.write('`')
|
||||
|
||||
_printed_line = ""
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
def split_line(line: str) -> list[str]:
|
||||
res = []
|
||||
|
||||
i = 0
|
||||
while i < len(line):
|
||||
if line[i] in ['@', '/', '¥']:
|
||||
res.append(line[i])
|
||||
elif line[i:i+3] == '!sd':
|
||||
res.append(line[i:i+3])
|
||||
i += 3
|
||||
elif line[i:i+2] in ['!d', '!w']:
|
||||
print("tefntyuf")
|
||||
x = i
|
||||
i += 2
|
||||
while i < len(line):
|
||||
if line[i].isdigit():
|
||||
print(x, i)
|
||||
i += 1
|
||||
continue
|
||||
|
||||
res.append(line[x:i])
|
||||
break
|
||||
|
||||
i += 1
|
||||
|
||||
return res
|
Loading…
Reference in New Issue