Handle symbols/commands at the start of line
This commit is contained in:
parent
f5d41d3068
commit
13f21c6d11
54
src/orig.py
54
src/orig.py
|
@ -9,6 +9,7 @@ import parser
|
|||
import flow
|
||||
import fix
|
||||
|
||||
def line_should_be_translated(line: str) -> bool:
|
||||
japanese_ranges = [
|
||||
(0x4E00, 0x9FFF), # Kanji
|
||||
(0x3040, 0x309F), # Hiragana
|
||||
|
@ -18,6 +19,28 @@ japanese_ranges = [
|
|||
(8220, 8220), # The character “
|
||||
]
|
||||
|
||||
|
||||
for start, end in japanese_ranges:
|
||||
if start <= ord(line[0]) <= end:
|
||||
return True
|
||||
|
||||
# if line starts with special commands
|
||||
if line.startswith(('!s', '!w', '!d', '@', '¥')):
|
||||
# ignore line after comment
|
||||
comment_i = line.find(';')
|
||||
if comment_i != -1:
|
||||
line = line[:comment_i]
|
||||
|
||||
# Check if line has japanese chars
|
||||
for c in line:
|
||||
for start, end in japanese_ranges:
|
||||
if start <= ord(c) <= end:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
|
||||
debug_current_line = -1
|
||||
|
||||
def process_sections():
|
||||
|
@ -50,8 +73,9 @@ def process_sections():
|
|||
origfile.close()
|
||||
|
||||
|
||||
def get_symbols(line: str) -> list[str]:
|
||||
def get_symbols(line: str) -> (str, list[str]):
|
||||
res = []
|
||||
start_symbol = ''
|
||||
|
||||
inbetween = 0
|
||||
i = 0
|
||||
|
@ -81,14 +105,23 @@ def get_symbols(line: str) -> list[str]:
|
|||
continue
|
||||
|
||||
# Only reaches this if it's a symbol
|
||||
#print(symbol)
|
||||
|
||||
# Each symbol acts as a separator between dialog texts, if we
|
||||
# have two symbols next to eachother, then we print more dialog
|
||||
# than we should. Concatenate consicutive symbols together to
|
||||
# prevent this
|
||||
if inbetween > 0:
|
||||
res.append(symbol)
|
||||
else:
|
||||
# Symbols at the start should not have dialog before them.
|
||||
# Treat them as a special "start_symbol"
|
||||
if len(res) == 0:
|
||||
start_symbol = symbol
|
||||
else:
|
||||
res[-1] += symbol
|
||||
inbetween = 0
|
||||
|
||||
return res
|
||||
return start_symbol, res
|
||||
|
||||
|
||||
# Given a set of translation files, the original file and the output file
|
||||
|
@ -103,19 +136,18 @@ def write_translated(outfile, origfile, translation_file_paths):
|
|||
debug_current_line += 1
|
||||
|
||||
# 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:
|
||||
found = True
|
||||
|
||||
if found:
|
||||
symbols = get_symbols(line)
|
||||
if line_should_be_translated(line):
|
||||
start, symbols = get_symbols(line)
|
||||
print("\n-", debug_current_line, transfilepath, symbols)
|
||||
|
||||
outfile.write('`')
|
||||
outfile.write(start)
|
||||
|
||||
_printed_line_jp = ""
|
||||
_printed_line_en = ""
|
||||
print([start])
|
||||
|
||||
_printed_line_jp = start
|
||||
_printed_line_en = start
|
||||
while True:
|
||||
_printed_line_jp += structure[0].text_jp
|
||||
_printed_line_en += structure[0].text_en
|
||||
|
|
Loading…
Reference in New Issue