Adjust csv and tyrano

This commit is contained in:
Dazed 2023-09-27 11:23:40 -05:00
parent 84d8019216
commit 78a8bc87c7
2 changed files with 8 additions and 6 deletions

View file

@ -41,7 +41,7 @@ def handleCSV(filename, estimate):
global ESTIMATE, TOKENS, TOTALTOKENS, TOTALCOST
ESTIMATE = estimate
with open('translated/' + filename, 'w+t', newline='', encoding='utf-16-le') as writeFile:
with open('translated/' + filename, 'w+t', newline='', encoding='utf-8') as writeFile:
start = time.time()
translatedData = openFiles(filename, writeFile)
@ -64,7 +64,7 @@ def handleCSV(filename, estimate):
return getResultString(['', TOTALTOKENS, None], end - start, 'TOTAL')
def openFiles(filename, writeFile):
with open('files/' + filename, 'r', encoding='utf-16-le') as readFile, writeFile:
with open('files/' + filename, 'r', encoding='utf-8') as readFile, writeFile:
translatedData = parseCSV(readFile, writeFile, filename)
return translatedData
@ -167,12 +167,13 @@ def translateCSV(row, pbar, writer, textHistory, format):
# Translate Everything
case '2':
for i in range(len(row)):
# This will allow you to ignore certain columns
if i not in [1]:
continue
jaString = row[i]
matchList = re.findall(r':name\[(.+?),.+?\](.+?[」)\"。]+)', jaString)
# Start Translation
for match in matchList:
speaker = match[0]
text = match[1]

View file

@ -153,9 +153,8 @@ def translateTyrano(data, pbar):
translatedText = translatedText.replace(char, '')
# Set Data
translatedText = translatedText.replace(' ', ' ')
data[i] = re.sub(r'(text=)\"(.+?)\"', rf'\1{translatedText}', data[i])
translatedText = 'text=\"' + translatedText.replace(' ', ' ') + '\"'
data[i] = re.sub(r'text=\"(.+?)\"', translatedText, data[i])
# Lines
elif '[p]' in data[i]:
@ -211,6 +210,8 @@ def translateTyrano(data, pbar):
while len(matchList[j]) < 100 and len(matchList) > j:
matchList[j:j+2] = [' '.join(matchList[j:j+2])]
if len(matchList) == j+1:
matchList[j] = matchList[j] + ' ' + translatedText
translatedText = ''
break
j+=1