Couple changes to onscripter
This commit is contained in:
parent
5edd1276d9
commit
c0a26bdcdd
1 changed files with 120 additions and 114 deletions
|
|
@ -77,7 +77,7 @@ def handleNScript(filename, estimate):
|
|||
|
||||
else:
|
||||
try:
|
||||
with open('translated/' + filename, 'w', encoding='shift_jis', errors='ignore') as outFile:
|
||||
with open('translated/' + filename, 'w', encoding='utf8', errors='ignore') as outFile:
|
||||
start = time.time()
|
||||
translatedData = openFiles(filename)
|
||||
|
||||
|
|
@ -172,7 +172,7 @@ def translateNScript(data, pbar, totalLines):
|
|||
speaker = response[0]
|
||||
tokens[0] += response[1][0]
|
||||
tokens[1] += response[1][1]
|
||||
data[i] = '【 ' + speaker + ' 】\n'
|
||||
data[i] = '>[' + speaker + ']\n'
|
||||
i += 1
|
||||
else:
|
||||
speaker = ''
|
||||
|
|
@ -200,144 +200,150 @@ def translateNScript(data, pbar, totalLines):
|
|||
|
||||
# Escape all '
|
||||
translatedText = translatedText.replace('\\', '')
|
||||
translatedText = translatedText.replace(' ', ' ')
|
||||
|
||||
# Set Data
|
||||
translatedText = data[i].replace(originalTextList[choice], translatedText)
|
||||
data[i] = translatedText
|
||||
data[i] = translatedText
|
||||
pbar.update(1)
|
||||
i += 1
|
||||
else:
|
||||
pbar.update(1)
|
||||
i += 1
|
||||
|
||||
# Lines
|
||||
matchList = re.findall(r'^[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9「」 >()].*', data[i])
|
||||
if len(matchList) > 0:
|
||||
currentGroup.append(matchList[0])
|
||||
if len(data) > i+1:
|
||||
if speaker == '':
|
||||
while '\n' != data[i+1] and '【' not in data[i+1]:
|
||||
if insertBool is True:
|
||||
data[i] = '\d\n'
|
||||
pbar.update(1)
|
||||
i += 1
|
||||
matchList = re.findall(r'^[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9「」 >()].*', data[i])
|
||||
if len(matchList) > 0:
|
||||
currentGroup.append(matchList[0])
|
||||
else:
|
||||
while ' ' in data[i+1][0] or '"' in data[i+1] or ')' in data[i+1] or ')' in data[i+1]:
|
||||
if insertBool is True:
|
||||
data[i] = '\d\n'
|
||||
pbar.update(1)
|
||||
i += 1
|
||||
matchList = re.findall(r'^[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9「」 >()].*', data[i])
|
||||
if len(matchList) > 0:
|
||||
currentGroup.append(matchList[0])
|
||||
# matchList = re.findall(r'^[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9「」 >()].*', data[i])
|
||||
# if len(matchList) > 0:
|
||||
# currentGroup.append(matchList[0])
|
||||
# if len(data) > i+1:
|
||||
# if speaker == '':
|
||||
# while '\n' != data[i+1] and '【' not in data[i+1]:
|
||||
# if insertBool is True:
|
||||
# data[i] = '\d\n'
|
||||
# pbar.update(1)
|
||||
# i += 1
|
||||
# matchList = re.findall(r'^[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9「」 >()].*', data[i])
|
||||
# if len(matchList) > 0:
|
||||
# currentGroup.append(matchList[0])
|
||||
# else:
|
||||
# while ' ' in data[i+1][0] or '"' in data[i+1] or ')' in data[i+1] or ')' in data[i+1]:
|
||||
# if insertBool is True:
|
||||
# data[i] = '\d\n'
|
||||
# pbar.update(1)
|
||||
# i += 1
|
||||
# matchList = re.findall(r'^[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9「」 >()].*', data[i])
|
||||
# if len(matchList) > 0:
|
||||
# currentGroup.append(matchList[0])
|
||||
|
||||
# Join up 401 groups for better translation.
|
||||
if len(currentGroup) > 0:
|
||||
finalJAString = ' '.join(currentGroup)
|
||||
oldjaString = finalJAString
|
||||
# # Join up 401 groups for better translation.
|
||||
# if len(currentGroup) > 0:
|
||||
# finalJAString = ' '.join(currentGroup)
|
||||
# oldjaString = finalJAString
|
||||
|
||||
# Remove any textwrap
|
||||
if FIXTEXTWRAP == True:
|
||||
finalJAString = finalJAString.replace('>', '')
|
||||
finalJAString = finalJAString.replace('\\', ' ')
|
||||
# # Remove any textwrap
|
||||
# if FIXTEXTWRAP == True:
|
||||
# finalJAString = finalJAString.replace('>', '')
|
||||
# finalJAString = finalJAString.replace('\\', ' ')
|
||||
|
||||
# Remove Extra Stuff bad for translation.
|
||||
finalJAString = finalJAString.replace('゙', '')
|
||||
finalJAString = finalJAString.replace('・', '.')
|
||||
finalJAString = finalJAString.replace('‶', '')
|
||||
finalJAString = finalJAString.replace('”', '')
|
||||
finalJAString = finalJAString.replace('―', '-')
|
||||
finalJAString = finalJAString.replace('ー', '-')
|
||||
finalJAString = finalJAString.replace('…', '...')
|
||||
finalJAString = re.sub(r'(\.{3}\.+)', '...', finalJAString)
|
||||
finalJAString = finalJAString.replace(' ', ' ')
|
||||
# # Remove Extra Stuff bad for translation.
|
||||
# finalJAString = finalJAString.replace('゙', '')
|
||||
# finalJAString = finalJAString.replace('・', '.')
|
||||
# finalJAString = finalJAString.replace('‶', '')
|
||||
# finalJAString = finalJAString.replace('”', '')
|
||||
# finalJAString = finalJAString.replace('―', '-')
|
||||
# finalJAString = finalJAString.replace('ー', '-')
|
||||
# finalJAString = finalJAString.replace('…', '...')
|
||||
# finalJAString = re.sub(r'(\.{3}\.+)', '...', finalJAString)
|
||||
# finalJAString = finalJAString.replace(' ', ' ')
|
||||
|
||||
# Furigana Removal
|
||||
matchList = re.findall(r'『\((.+)/.*?』', finalJAString)
|
||||
if len(matchList) > 0:
|
||||
finalJAString = finalJAString.replace(matchList[0][0], matchList[0][1])
|
||||
# # Furigana Removal
|
||||
# matchList = re.findall(r'『\((.+)/.*?』', finalJAString)
|
||||
# if len(matchList) > 0:
|
||||
# finalJAString = finalJAString.replace(matchList[0][0], matchList[0][1])
|
||||
|
||||
# Add Speaker (If there is one)
|
||||
if speaker != '':
|
||||
finalJAString = f'{speaker}: {finalJAString}'
|
||||
# # Add Speaker (If there is one)
|
||||
# if speaker != '':
|
||||
# finalJAString = f'{speaker}: {finalJAString}'
|
||||
|
||||
# [Passthrough 1] Pulling From File
|
||||
if insertBool is False:
|
||||
# Append to List and Clear Values
|
||||
batch.append(finalJAString)
|
||||
speaker = ''
|
||||
# # [Passthrough 1] Pulling From File
|
||||
# if insertBool is False:
|
||||
# # Append to List and Clear Values
|
||||
# batch.append(finalJAString)
|
||||
# speaker = ''
|
||||
|
||||
# Translate Batch if Full
|
||||
if len(batch) == BATCHSIZE:
|
||||
# Translate
|
||||
response = translateGPT(batch, textHistory, True)
|
||||
tokens[0] += response[1][0]
|
||||
tokens[1] += response[1][1]
|
||||
translatedBatch = response[0]
|
||||
textHistory = translatedBatch[-10:]
|
||||
# # Translate Batch if Full
|
||||
# if len(batch) == BATCHSIZE:
|
||||
# # Translate
|
||||
# response = translateGPT(batch, textHistory, True)
|
||||
# tokens[0] += response[1][0]
|
||||
# tokens[1] += response[1][1]
|
||||
# translatedBatch = response[0]
|
||||
# textHistory = translatedBatch[-10:]
|
||||
|
||||
# Set Values
|
||||
if len(batch) == len(translatedBatch):
|
||||
i = batchStartIndex
|
||||
insertBool = True
|
||||
# # Set Values
|
||||
# if len(batch) == len(translatedBatch):
|
||||
# i = batchStartIndex
|
||||
# insertBool = True
|
||||
|
||||
# Mismatch
|
||||
else:
|
||||
pbar.write(f'Mismatch: {batchStartIndex} - {i}')
|
||||
MISMATCH.append(batch)
|
||||
batchStartIndex = i
|
||||
batch.clear()
|
||||
# # Mismatch
|
||||
# else:
|
||||
# pbar.write(f'Mismatch: {batchStartIndex} - {i}')
|
||||
# MISMATCH.append(batch)
|
||||
# batchStartIndex = i
|
||||
# batch.clear()
|
||||
|
||||
i += 1
|
||||
if insertBool is True:
|
||||
pbar.update(1)
|
||||
currentGroup = []
|
||||
# i += 1
|
||||
# if insertBool is True:
|
||||
# pbar.update(1)
|
||||
# currentGroup = []
|
||||
|
||||
# [Passthrough 2] Setting Data
|
||||
else:
|
||||
# Get Text
|
||||
translatedText = translatedBatch[0]
|
||||
translatedText = translatedText.replace('\\"', '\"')
|
||||
translatedText = translatedText.replace('[', '(')
|
||||
translatedText = translatedText.replace(']', ')')
|
||||
# # [Passthrough 2] Setting Data
|
||||
# else:
|
||||
# # Get Text
|
||||
# translatedText = translatedBatch[0]
|
||||
# translatedText = translatedText.replace('\\"', '\"')
|
||||
# translatedText = translatedText.replace('[', '(')
|
||||
# translatedText = translatedText.replace(']', ')')
|
||||
|
||||
# Remove added speaker
|
||||
translatedText = re.sub(r'^.+?:\s', '', translatedText)
|
||||
# # Remove added speaker
|
||||
# translatedText = re.sub(r'^.+?:\s', '', translatedText)
|
||||
|
||||
# Textwrap
|
||||
translatedText = textwrap.fill(translatedText, width=WIDTH)
|
||||
textList = translatedText.split('\n')
|
||||
# # Textwrap
|
||||
# translatedText = textwrap.fill(translatedText, width=WIDTH)
|
||||
# textList = translatedText.split('\n')
|
||||
|
||||
# Set Text
|
||||
data[i] = '\d\n'
|
||||
counter = 0
|
||||
for line in textList:
|
||||
# Wordwrap Text
|
||||
line = textwrap.fill(line, width=WIDTH)
|
||||
# # Set Text
|
||||
# data[i] = '\d\n'
|
||||
# counter = 0
|
||||
# for line in textList:
|
||||
# # Wordwrap Text
|
||||
# line = textwrap.fill(line, width=WIDTH)
|
||||
|
||||
# Set
|
||||
data.insert(i, '>' + line.strip() + '\n')
|
||||
counter += 1
|
||||
i+=1
|
||||
# # Set
|
||||
# data.insert(i, '>' + line.strip() + '\n')
|
||||
# counter += 1
|
||||
# i+=1
|
||||
|
||||
# Go to new window if too long
|
||||
if counter >= 4:
|
||||
data[i-1] = data[i-1].replace('\n', '\\\n')
|
||||
counter = 0
|
||||
if '\\' not in data[i-1]:
|
||||
data[i-1] = data[i-1].replace('\n', '\\\n')
|
||||
translatedBatch.pop(0)
|
||||
speaker = ''
|
||||
currentGroup = []
|
||||
# # Go to new window if too long
|
||||
# if counter >= 4:
|
||||
# data[i-1] = data[i-1].replace('\n', '\\\n')
|
||||
# counter = 0
|
||||
# if '\\' not in data[i-1]:
|
||||
# data[i-1] = data[i-1].replace('\n', '\\\n')
|
||||
# translatedBatch.pop(0)
|
||||
# speaker = ''
|
||||
# currentGroup = []
|
||||
|
||||
# If Batch is empty. Move on.
|
||||
if len(translatedBatch) == 0:
|
||||
insertBool = False
|
||||
batchStartIndex = i
|
||||
batch.clear()
|
||||
# # If Batch is empty. Move on.
|
||||
# if len(translatedBatch) == 0:
|
||||
# insertBool = False
|
||||
# batchStartIndex = i
|
||||
# batch.clear()
|
||||
|
||||
# Nothing relevant. Skip Line.
|
||||
else:
|
||||
i += 1
|
||||
if insertBool is True:
|
||||
if insertBool is False:
|
||||
pbar.update(1)
|
||||
|
||||
# Translate Batch if not empty and EOF
|
||||
|
|
|
|||
Loading…
Reference in a new issue