Fixes and remove subvar for now

This commit is contained in:
DazedAnon 2024-10-12 11:15:07 -05:00
parent 83e6596d86
commit 233cdd1f76
3 changed files with 54 additions and 47 deletions

View file

@ -67,6 +67,10 @@ def handleImages(folderName, estimate):
# Translate Strings
translatedData = openFiles(f"files/{folderName}")
# Custom Names
# customList = [[], []]
# customList = processImagesDir('Custom', customList)
# Write Strings to Images
if not ESTIMATE:
if not os.path.exists(f"translated/{folderName}"):
@ -82,6 +86,7 @@ def handleImages(folderName, estimate):
image.save(
rf"translated/{folderName}/{translatedList[i]}.png", quality=100
)
# customList[0].pop(0)
except Exception as e:
PBAR.write(f"{translatedList[i]}: {str(e)}")
# Ignore Error
@ -184,7 +189,7 @@ def getFontSize(text, image_width, image_height, font_path):
(0, 0), text, font=font
)
text_width = text_bbox[2] - text_bbox[0]
text_height = text_bbox[3] - text_bbox[1] + 5
text_height = text_bbox[3] - text_bbox[1] + 10
if text_width <= image_width and text_height <= image_height:
return font_size
@ -218,8 +223,8 @@ def stringToImage(
text_bbox = draw.textbbox((0, 0), text, font=font)
text_width = text_bbox[2] - text_bbox[0]
text_height = text_bbox[3] - text_bbox[1]
x = (scaled_width - text_width) // 2
y = (scaled_height - text_height) // 2
x = 0
y = 0
# Draw the text on the image
draw.text((x, y), text, font=font, fill=(255, 255, 255, 255))
@ -246,7 +251,7 @@ def getImageDimensions(file_path):
def processImagesDir(directory_path, imageList):
for file_name in os.listdir(directory_path):
# .png and Japanese
if ".png" in file_name and file_name.replace(".png", "") in VOCAB:
if ".png" in file_name:
file_path = os.path.join(directory_path, file_name)
if os.path.isfile(file_path):
# Check if the file is an image
@ -276,7 +281,7 @@ def processImagesDir(directory_path, imageList):
imageList[0].append(
line
) # Using strip() to remove any extra newlines or spaces
imageList[1].append([150, 22])
imageList[1].append([104, 15])
except FileNotFoundError:
print(f"The file at {file_path} was not found.")
except IOError:

View file

@ -67,9 +67,9 @@ POSITION = 0
LEAVE = False
# Dialogue / Scroll / Choices (Main Codes)
CODE401 = True
CODE401 = False
CODE405 = False
CODE102 = True
CODE102 = False
# Optional
CODE101 = False # Turn this one when names exist in 101
@ -80,7 +80,7 @@ CODE122 = False
# Other
CODE355655 = False
CODE357 = False
CODE357 = True
CODE657 = False
CODE356 = False
CODE320 = False
@ -1509,14 +1509,14 @@ def searchCodes(page, pbar, jobList, filename):
translatedText = translatedText.replace(char, "")
# Textwrap
translatedText = textwrap.fill(translatedText, 100)
translatedText = translatedText.replace("- ", "-")
if acExist:
translatedText = f'\\ac {translatedText.replace('\n', '\n\\ac ')}'
# translatedText = textwrap.fill(translatedText, LISTWIDTH)
# translatedText = translatedText.replace("- ", "-")
# if acExist:
# translatedText = f'\\ac {translatedText.replace('\n', '\n\\ac ')}'
# Set
codeList[i]["parameters"][3][argVar] = translatedText
codeList[i]["parameters"][3]['fontSize'] = "18"
# codeList[i]["parameters"][3]['fontSize'] = "18"
list357.pop(0)
## Event Code: 657 [Picture Text] [Optional]
@ -1996,8 +1996,9 @@ def searchCodes(page, pbar, jobList, filename):
ifVar = ""
ifList = re.findall(r"([ei][nf]\(.+?\)\)?\)?)", jaString)
if len(ifList) != 0:
jaString = jaString.replace(ifList[0], "")
ifVar = ifList[0]
for var in ifList:
jaString = jaString.replace(var, "")
ifVar += var
varList.append(ifVar)
# Append to List
@ -2535,38 +2536,38 @@ def getSpeaker(speaker):
return [speaker, [0, 0]]
def subVars(jaString):
jaString = jaString.replace("\u3000", " ")
# def subVars(jaString):
# jaString = jaString.replace("\u3000", " ")
# Formatting
count = 0
codeList = re.findall(r"[\\]+[\w]+\[[a-zA-Z0-9\\\[\]\_,\s-]+?\]", jaString)
codeList = set(codeList)
if len(codeList) != 0:
for var in codeList:
jaString = jaString.replace(var, "[FCode_" + str(count) + "]")
count += 1
# # Formatting
# count = 0
# codeList = re.findall(r"[\\]+[\w]+\[[a-zA-Z0-9\\\[\]\_,\s-]+?\]", jaString)
# codeList = set(codeList)
# if len(codeList) != 0:
# for var in codeList:
# jaString = jaString.replace(var, "[FCode_" + str(count) + "]")
# count += 1
# Put all lists in list and return
return [jaString, codeList]
# # Put all lists in list and return
# return [jaString, codeList]
def resubVars(translatedText, codeList):
# Fix Spacing and ChatGPT Nonsense
matchList = re.findall(r"\[\s?.+?\s?\]", translatedText)
if len(matchList) > 0:
for match in matchList:
text = match.strip()
translatedText = translatedText.replace(match, text)
# def resubVars(translatedText, codeList):
# # Fix Spacing and ChatGPT Nonsense
# matchList = re.findall(r"\[\s?.+?\s?\]", translatedText)
# if len(matchList) > 0:
# for match in matchList:
# text = match.strip()
# translatedText = translatedText.replace(match, text)
# Formatting
count = 0
if len(codeList) != 0:
for var in codeList:
translatedText = translatedText.replace("[FCode_" + str(count) + "]", var)
count += 1
# # Formatting
# count = 0
# if len(codeList) != 0:
# for var in codeList:
# translatedText = translatedText.replace("[FCode_" + str(count) + "]", var)
# count += 1
return translatedText
# return translatedText
def batchList(input_list, batch_size):
@ -2649,7 +2650,7 @@ def cleanTranslatedText(translatedText, varResponse):
# Elongate Long Dashes (Since GPT Ignores them...)
translatedText = elongateCharacters(translatedText)
translatedText = resubVars(translatedText, varResponse[1])
# translatedText = resubVars(translatedText, varResponse[1])
return translatedText
@ -2729,10 +2730,11 @@ def translateGPT(text, history, fullPromptFlag):
if isinstance(tItem, list):
payload = {f"Line{i+1}": string for i, string in enumerate(tItem)}
payload = json.dumps(payload, indent=4, ensure_ascii=False)
varResponse = subVars(payload)
# varResponse = subVars(payload)
varResponse = [payload,[]]
subbedT = varResponse[0]
else:
varResponse = subVars(tItem)
varResponse = [tItem,[]]
subbedT = varResponse[0]
# Things to Check before starting translation

View file

@ -963,7 +963,7 @@ def searchDB(events, pbar, jobList, filename):
scenarioList[2].pop(0)
# Grab Items
if table["name"] == "武器タイプ" and ITEMFLAG == True:
if table["name"] == "モンスター図鑑" and ITEMFLAG == True:
with open("translations.txt", "a", encoding="utf-8") as file:
for item in table["data"]:
dataList = item["data"]
@ -971,7 +971,7 @@ def searchDB(events, pbar, jobList, filename):
# Parse #
for j in range(len(dataList)):
# Name
if dataList[j].get("name") == "武器タイプ":
if dataList[j].get("name") == "NULL":
# Pass 1 (Grab Data)
if setData == False:
if dataList[j].get("value") != "":
@ -991,7 +991,7 @@ def searchDB(events, pbar, jobList, filename):
itemList[0].pop(0)
# Description 1 (You are my specialz)
if dataList[j].get("name") == "NULL":
if dataList[j].get("name") == "説明文":
# Clean String
fontSize = 14
translatedText = ""