Couple of adjustments

This commit is contained in:
DazedAnon 2024-07-21 10:20:15 -05:00
parent e2af90ec60
commit 02fa8df4bc
2 changed files with 81 additions and 40 deletions

View file

@ -170,11 +170,10 @@ def translateOnscripter(data, pbar, filename, translatedList):
PBAR = pbar
i = 0
# Dialogue
while i < len(data):
voice = False
speaker = ''
regex = r'^([\u3000「【[][^\n]+)'
# Lines
regex = r'^([\u3000「【[][^\n]+)'
match = re.search(regex, data[i])
if match != None and match.group(1) != '':
originalString = match.group(1)
@ -191,7 +190,7 @@ def translateOnscripter(data, pbar, filename, translatedList):
jaString = jaString.translate(wide_to_ascii)
# Remove any textwrap and \u3000 and \
jaString = jaString.replace('\n', ' ')
jaString = jaString.replace('\n', '')
jaString = jaString.replace('\u3000', '')
jaString = jaString.replace('\\', '')
jaString = jaString.replace(' ', ')')
@ -222,41 +221,53 @@ def translateOnscripter(data, pbar, filename, translatedList):
translatedText = textwrap.fill(translatedText, width=WIDTH)
translatedText = translatedText.replace('\n', '\n\u3000')
# Split the string into lines
lines = translatedText.split('\n')
# Add a backslash after every 3rd line
j = 0
while j < len(lines):
if j == 4:
lines[j-1] = f'{lines[j-1]}\\'
lines[j] = f'\n{lines[j]}'
j += 1
# Join the lines back into a single string
translatedText = '\n'.join(lines)
# Remove Double Spaces
translatedText = translatedText.replace(' ', ' ')
# Convert to Wide
translatedText = translatedText.translate(ascii_to_wide)
# Add Break
translatedText = translatedText.replace('\"', '\'')
translatedText = f'\u3000{translatedText}\\'
# Unconvert Codes
matchList = re.findall(r'([].+?)[^\w]', translatedText)
if matchList:
for match in matchList:
translatedText = translatedText.replace(match, match.translate(wide_to_ascii))
# Unconvert Color Codes
matchList = re.findall(r'([][\w\d]{6})', translatedText)
if matchList:
for match in matchList:
translatedText = translatedText.replace(match, match.translate(wide_to_ascii))
# Unconvert Variables
matchList = re.findall(r'([]\w.+?)[^\w_]', translatedText)
if matchList:
for match in matchList:
translatedText = translatedText.replace(match, match.translate(wide_to_ascii))
# Fix Broken Code
matchList = re.findall(r'( .*)', translatedText, re.DOTALL)
if matchList:
for match in matchList:
code = match.replace('\n', ' ')
translatedText = translatedText.replace(match, '\\' + f'{code.translate(wide_to_ascii)}'.replace('\\', ''))
# Fix Formatting
translatedText = fixText(translatedText)
# Set Data
data[i] = data[i].replace(originalString, translatedText)
data[i] = data[i].replace(originalString, f'{translatedText}')
i += 1
# Choices
elif 'csel' in data[i] and translatedList != []:
choiceList = []
jaString = data[i]
choiceList = re.findall(r'\"(.*?)\"', jaString)
if len(choiceList) > 0:
# Translate
response = translateGPT(choiceList, 'This will be a dialogue option', True)
translatedTextList = response[0]
tokens[0] += response[1][0]
tokens[1] += response[1][1]
# Set Data
for j in range(len(translatedTextList)):
# Convert to Wide
translatedText = translatedTextList[j].translate(ascii_to_wide)
# Set
data[i] = data[i].replace(choiceList[j], translatedText)
i += 1
# Nothing relevant. Skip Line.
@ -286,6 +297,37 @@ def translateOnscripter(data, pbar, filename, translatedList):
MISMATCH.append(filename)
return tokens
def fixText(translatedText):
# Add Break
translatedText = translatedText.replace('\"', '\'')
translatedText = f'\u3000{translatedText}\\'
# Unconvert Codes
matchList = re.findall(r'([].+?)[^\w]', translatedText)
if matchList:
for match in matchList:
translatedText = translatedText.replace(match, match.translate(wide_to_ascii))
# Unconvert Color Codes
matchList = re.findall(r'([][\w\d]{6})', translatedText)
if matchList:
for match in matchList:
translatedText = translatedText.replace(match, match.translate(wide_to_ascii))
# Unconvert Variables
matchList = re.findall(r'([]\w.+?)[^\w_]', translatedText)
if matchList:
for match in matchList:
translatedText = translatedText.replace(match, match.translate(wide_to_ascii))
# Unconvert Backslashes
matchList = re.findall(r'', translatedText)
if matchList:
for match in matchList:
translatedText = translatedText.replace(match, match.translate(wide_to_ascii))
return translatedText
# Save some money and enter the character before translation
def getSpeaker(speaker):
match speaker:

View file

@ -162,11 +162,11 @@ def translateRegex(data, pbar, filename, translatedList):
while i < len(data):
voice = False
speaker = ''
if 'MSG' in data[i] or 'SYSTEM' in data[i]:
if 'mov' in data[i]:
# Lines
match = re.search(r'.+ .+ MSG.*? .+ \u3000?(.+) .+ .+ .+ ', data[i])
match = re.search(r'mov\s\$\d+?,"(.*?)"', data[i])
if match == None:
match = re.search(r'.+ .+ SYSTEM.*? .+ \u3000?(.+) .+ .+ .+ ', data[i])
match = re.search(r'mov\s\$\d+?,"(.*?)"', data[i])
if match != None and match.group(1) != '':
originalString = match.group(1)
# Pass 1
@ -175,7 +175,7 @@ def translateRegex(data, pbar, filename, translatedList):
jaString = match.group(1)
# Remove any textwrap
jaString = jaString.replace('<br>', ' ')
jaString = jaString.replace('\n', ' ')
# Add String
stringList.append(jaString.strip())
@ -194,7 +194,6 @@ def translateRegex(data, pbar, filename, translatedList):
# Textwrap
translatedText = textwrap.fill(translatedText, width=WIDTH)
translatedText = translatedText.replace('\n', '<br>')
# Set Data
data[i] = data[i].replace(originalString, translatedText)
@ -213,7 +212,7 @@ def translateRegex(data, pbar, filename, translatedList):
pbar.refresh()
# Translate
response = translateGPT(stringList, '', True, pbar, filename)
response = translateGPT(stringList, 'Reply with the English TL of the NPC Name', True, pbar, filename)
tokens[0] += response[1][0]
tokens[1] += response[1][1]
translatedList = response[0]