Fix subVars
This commit is contained in:
parent
447e3f9ef2
commit
5615071dd0
6 changed files with 64 additions and 53 deletions
|
|
@ -242,7 +242,7 @@ def subVars(jaString):
|
|||
count = 0
|
||||
colorList = re.findall(r'[\\]+[cC]\[[0-9]+\]', jaString)
|
||||
colorList = set(colorList)
|
||||
if len(iconList) != 0:
|
||||
if len(colorList) != 0:
|
||||
for color in colorList:
|
||||
jaString = jaString.replace(color, '<C' + str(count) + '>')
|
||||
count += 1
|
||||
|
|
@ -251,7 +251,7 @@ def subVars(jaString):
|
|||
count = 0
|
||||
nameList = re.findall(r'[\\]+[nN]\[[0-9]+\]', jaString)
|
||||
nameList = set(nameList)
|
||||
if len(iconList) != 0:
|
||||
if len(nameList) != 0:
|
||||
for name in nameList:
|
||||
jaString = jaString.replace(name, '<N' + str(count) + '>')
|
||||
count += 1
|
||||
|
|
@ -260,7 +260,7 @@ def subVars(jaString):
|
|||
count = 0
|
||||
varList = re.findall(r'[\\]+[vV]\[[0-9]+\]', jaString)
|
||||
varList = set(varList)
|
||||
if len(iconList) != 0:
|
||||
if len(varList) != 0:
|
||||
for var in varList:
|
||||
jaString = jaString.replace(var, '<V' + str(count) + '>')
|
||||
count += 1
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ def subVars(jaString):
|
|||
count = 0
|
||||
colorList = re.findall(r'[\\]+[cC]\[[0-9]+\]', jaString)
|
||||
colorList = set(colorList)
|
||||
if len(iconList) != 0:
|
||||
if len(colorList) != 0:
|
||||
for color in colorList:
|
||||
jaString = jaString.replace(color, '<C' + str(count) + '>')
|
||||
count += 1
|
||||
|
|
@ -183,7 +183,7 @@ def subVars(jaString):
|
|||
count = 0
|
||||
nameList = re.findall(r'[\\]+[nN]\[[0-9]+\]', jaString)
|
||||
nameList = set(nameList)
|
||||
if len(iconList) != 0:
|
||||
if len(nameList) != 0:
|
||||
for name in nameList:
|
||||
jaString = jaString.replace(name, '<N' + str(count) + '>')
|
||||
count += 1
|
||||
|
|
@ -192,7 +192,7 @@ def subVars(jaString):
|
|||
count = 0
|
||||
varList = re.findall(r'[\\]+[vV]\[[0-9]+\]', jaString)
|
||||
varList = set(varList)
|
||||
if len(iconList) != 0:
|
||||
if len(varList) != 0:
|
||||
for var in varList:
|
||||
jaString = jaString.replace(var, '<V' + str(count) + '>')
|
||||
count += 1
|
||||
|
|
|
|||
|
|
@ -1348,7 +1348,7 @@ def subVars(jaString):
|
|||
count = 0
|
||||
colorList = re.findall(r'[\\]+[cC]\[[0-9]+\]', jaString)
|
||||
colorList = set(colorList)
|
||||
if len(iconList) != 0:
|
||||
if len(colorList) != 0:
|
||||
for color in colorList:
|
||||
jaString = jaString.replace(color, '<C' + str(count) + '>')
|
||||
count += 1
|
||||
|
|
@ -1357,7 +1357,7 @@ def subVars(jaString):
|
|||
count = 0
|
||||
nameList = re.findall(r'[\\]+[nN]\[[0-9]+\]', jaString)
|
||||
nameList = set(nameList)
|
||||
if len(iconList) != 0:
|
||||
if len(nameList) != 0:
|
||||
for name in nameList:
|
||||
jaString = jaString.replace(name, '<N' + str(count) + '>')
|
||||
count += 1
|
||||
|
|
@ -1366,7 +1366,7 @@ def subVars(jaString):
|
|||
count = 0
|
||||
varList = re.findall(r'[\\]+[vV]\[[0-9]+\]', jaString)
|
||||
varList = set(varList)
|
||||
if len(iconList) != 0:
|
||||
if len(varList) != 0:
|
||||
for var in varList:
|
||||
jaString = jaString.replace(var, '<V' + str(count) + '>')
|
||||
count += 1
|
||||
|
|
|
|||
|
|
@ -862,21 +862,31 @@ def searchCodes(page, pbar):
|
|||
jaString = codeList[i]['parameters'][0]
|
||||
if type(jaString) != str:
|
||||
continue
|
||||
|
||||
# Force Speaker
|
||||
if 'natu' in jaString:
|
||||
speaker = 'Natsu'
|
||||
continue
|
||||
elif 'kotohana' in jaString:
|
||||
speaker = 'Kotohana'
|
||||
continue
|
||||
elif 'aoi' in jaString:
|
||||
speaker = 'Aoi'
|
||||
continue
|
||||
elif 'misaki' in jaString:
|
||||
speaker = 'Misaki'
|
||||
continue
|
||||
elif 'koume' in jaString:
|
||||
speaker = 'Koume'
|
||||
continue
|
||||
elif 'titose' in jaString:
|
||||
speaker = 'Chitose'
|
||||
continue
|
||||
else:
|
||||
speaker = 'Unknown'
|
||||
|
||||
# Definitely don't want to mess with files
|
||||
if '_' in jaString:
|
||||
if 'natu' in jaString:
|
||||
speaker = 'Natu'
|
||||
elif 'kotohana' in jaString:
|
||||
speaker = 'Kotohana'
|
||||
elif 'aoi' in jaString:
|
||||
speaker = 'Aoi'
|
||||
elif 'misaki' in jaString:
|
||||
speaker = 'Misaki'
|
||||
elif 'koume' in jaString:
|
||||
speaker = 'Koume'
|
||||
elif 'titose' in jaString:
|
||||
speaker = 'Chitose'
|
||||
continue
|
||||
|
||||
# If there isn't any Japanese in the text just skip
|
||||
|
|
@ -1385,7 +1395,7 @@ def subVars(jaString):
|
|||
count = 0
|
||||
colorList = re.findall(r'[\\]+[cC]\[[0-9]+\]', jaString)
|
||||
colorList = set(colorList)
|
||||
if len(iconList) != 0:
|
||||
if len(colorList) != 0:
|
||||
for color in colorList:
|
||||
jaString = jaString.replace(color, '<C' + str(count) + '>')
|
||||
count += 1
|
||||
|
|
@ -1394,7 +1404,7 @@ def subVars(jaString):
|
|||
count = 0
|
||||
nameList = re.findall(r'[\\]+[nN]\[[0-9]+\]', jaString)
|
||||
nameList = set(nameList)
|
||||
if len(iconList) != 0:
|
||||
if len(nameList) != 0:
|
||||
for name in nameList:
|
||||
jaString = jaString.replace(name, '<N' + str(count) + '>')
|
||||
count += 1
|
||||
|
|
@ -1403,7 +1413,7 @@ def subVars(jaString):
|
|||
count = 0
|
||||
varList = re.findall(r'[\\]+[vV]\[[0-9]+\]', jaString)
|
||||
varList = set(varList)
|
||||
if len(iconList) != 0:
|
||||
if len(varList) != 0:
|
||||
for var in varList:
|
||||
jaString = jaString.replace(var, '<V' + str(count) + '>')
|
||||
count += 1
|
||||
|
|
@ -1467,7 +1477,7 @@ def translateGPT(t, history, fullPromptFlag):
|
|||
subbedT = varResponse[0]
|
||||
|
||||
# If there isn't any Japanese in the text just skip
|
||||
if not re.search(r'[一-龠]+|[ぁ-ゔ]+|[ァ-ヴー]+', subbedT):
|
||||
if not re.search(r'[一-龠]+|[ぁ-ゔ]+|[ァ-ヴ]+', subbedT):
|
||||
return(t, 0)
|
||||
|
||||
"""Translate text using GPT"""
|
||||
|
|
|
|||
|
|
@ -222,7 +222,7 @@ def subVars(jaString):
|
|||
count = 0
|
||||
colorList = re.findall(r'[\\]+[cC]\[[0-9]+\]', jaString)
|
||||
colorList = set(colorList)
|
||||
if len(iconList) != 0:
|
||||
if len(colorList) != 0:
|
||||
for color in colorList:
|
||||
jaString = jaString.replace(color, '<C' + str(count) + '>')
|
||||
count += 1
|
||||
|
|
@ -231,7 +231,7 @@ def subVars(jaString):
|
|||
count = 0
|
||||
nameList = re.findall(r'[\\]+[nN]\[[0-9]+\]', jaString)
|
||||
nameList = set(nameList)
|
||||
if len(iconList) != 0:
|
||||
if len(nameList) != 0:
|
||||
for name in nameList:
|
||||
jaString = jaString.replace(name, '<N' + str(count) + '>')
|
||||
count += 1
|
||||
|
|
@ -240,7 +240,7 @@ def subVars(jaString):
|
|||
count = 0
|
||||
varList = re.findall(r'[\\]+[vV]\[[0-9]+\]', jaString)
|
||||
varList = set(varList)
|
||||
if len(iconList) != 0:
|
||||
if len(varList) != 0:
|
||||
for var in varList:
|
||||
jaString = jaString.replace(var, '<V' + str(count) + '>')
|
||||
count += 1
|
||||
|
|
|
|||
|
|
@ -302,47 +302,48 @@ def subVars(jaString):
|
|||
allList = [iconList, colorList, nameList, varList]
|
||||
return [jaString, allList]
|
||||
|
||||
def resubVars(translatedText, allList):
|
||||
# Fix Spacing and ChatGPT Nonsense
|
||||
matchList = re.findall(r'<\s?.+?\s?>', translatedText)
|
||||
if len(matchList) > 0:
|
||||
for match in matchList:
|
||||
text = match.replace(' ', '')
|
||||
translatedText = translatedText.replace(match, text)
|
||||
def subVars(jaString):
|
||||
jaString = jaString.replace('\u3000', ' ')
|
||||
|
||||
# Icons
|
||||
count = 0
|
||||
if len(allList[0]) != 0:
|
||||
for var in allList[0]:
|
||||
translatedText = translatedText.replace('<I' + str(count) + '>', var)
|
||||
iconList = re.findall(r'[\\]+[iI]\[[0-9]+\]', jaString)
|
||||
iconList = set(iconList)
|
||||
if len(iconList) != 0:
|
||||
for icon in iconList:
|
||||
jaString = jaString.replace(icon, '<I' + str(count) + '>')
|
||||
count += 1
|
||||
|
||||
# Colors
|
||||
count = 0
|
||||
if len(allList[1]) != 0:
|
||||
for var in allList[1]:
|
||||
translatedText = translatedText.replace('<C' + str(count) + '>', var)
|
||||
colorList = re.findall(r'[\\]+[cC]\[[0-9]+\]', jaString)
|
||||
colorList = set(colorList)
|
||||
if len(colorList) != 0:
|
||||
for color in colorList:
|
||||
jaString = jaString.replace(color, '<C' + str(count) + '>')
|
||||
count += 1
|
||||
|
||||
# Names
|
||||
count = 0
|
||||
if len(allList[1]) != 0:
|
||||
for var in allList[2]:
|
||||
translatedText = translatedText.replace('<N' + str(count) + '>', var)
|
||||
nameList = re.findall(r'[\\]+[nN]\[[0-9]+\]', jaString)
|
||||
nameList = set(nameList)
|
||||
if len(nameList) != 0:
|
||||
for name in nameList:
|
||||
jaString = jaString.replace(name, '<N' + str(count) + '>')
|
||||
count += 1
|
||||
|
||||
# Vars
|
||||
# Variables
|
||||
count = 0
|
||||
if len(allList[1]) != 0:
|
||||
for var in allList[3]:
|
||||
translatedText = translatedText.replace('<V' + str(count) + '>', var)
|
||||
varList = re.findall(r'[\\]+[vV]\[[0-9]+\]', jaString)
|
||||
varList = set(varList)
|
||||
if len(varList) != 0:
|
||||
for var in varList:
|
||||
jaString = jaString.replace(var, '<V' + str(count) + '>')
|
||||
count += 1
|
||||
|
||||
# Remove Color Variables Spaces
|
||||
# if '\\c' in translatedText:
|
||||
# translatedText = re.sub(r'\s*(\\+c\[[1-9]+\])\s*', r' \1', translatedText)
|
||||
# translatedText = re.sub(r'\s*(\\+c\[0+\])', r'\1', translatedText)
|
||||
return translatedText
|
||||
# Put all lists in list and return
|
||||
allList = [iconList, colorList, nameList, varList]
|
||||
return [jaString, allList]
|
||||
|
||||
@retry(exceptions=Exception, tries=5, delay=5)
|
||||
def translateGPT(t, history, fullPromptFlag):
|
||||
|
|
|
|||
Loading…
Reference in a new issue