diff --git a/modules/alice.py b/modules/alice.py index e02e99e..2b16f19 100644 --- a/modules/alice.py +++ b/modules/alice.py @@ -80,9 +80,7 @@ def handleAlice(filename, estimate): # Print any errors on maps if len(MISMATCH) > 0: - return ( - totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET - ) + return totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET else: return totalString @@ -130,13 +128,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] == None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: @@ -165,9 +157,7 @@ def parseText(data, filename): totalLines = len(linesList) global LOCK - with tqdm( - bar_format=BAR_FORMAT, position=POSITION, total=totalLines, leave=LEAVE - ) as pbar: + with tqdm(bar_format=BAR_FORMAT, position=POSITION, total=totalLines, leave=LEAVE) as pbar: pbar.desc = filename pbar.total = totalLines try: @@ -208,9 +198,7 @@ def translateLines(linesList, pbar): jaString = re.sub(r"\\n", " ", jaString) # Grab Speaker - speakerMatch = re.findall( - r"s\[[0-9]+\] = \"([^/]+)\"", linesList[i - 1] - ) + speakerMatch = re.findall(r"s\[[0-9]+\] = \"([^/]+)\"", linesList[i - 1]) if len(speakerMatch) > 0: # If there isn't any Japanese in the text just skip if ( @@ -228,15 +216,12 @@ def translateLines(linesList, pbar): # Check if next line should be merged if insertBool is True: - linesList[i] = re.sub( - r"(s\[[0-9]+\]) = \"(.+)\"", r'\1 = ""', linesList[i] - ) + linesList[i] = re.sub(r"(s\[[0-9]+\]) = \"(.+)\"", r'\1 = ""', linesList[i]) linesList[i] = linesList[i].replace(";", "") start = i while ( len(linesList) > i + 1 - and re.search(r"s\[[0-9]+\] = \"\s+(.*)\"", linesList[i + 1]) - != None + and re.search(r"s\[[0-9]+\] = \"\s+(.*)\"", linesList[i + 1]) != None ): multiLine = True i += 1 @@ -465,9 +450,7 @@ def batchList(input_list, batch_size): if not isinstance(batch_size, int) or batch_size <= 0: raise ValueError("batch_size must be a positive integer") - return [ - input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size) - ] + return [input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size)] def createContext(fullPromptFlag, subbedT): @@ -592,9 +575,7 @@ def translateGPT(text, history, fullPromptFlag): for index, tItem in enumerate(tList): # Before sending to translation, if we have a list of items, add the formatting if isinstance(tItem, list): - payload = "\n".join( - [f"`{item}`" for i, item in enumerate(tItem)] - ) + payload = "\n".join([f"`{item}`" for i, item in enumerate(tItem)]) payload = payload.replace("``", "`Placeholder Text`") varResponse = subVars(payload) subbedT = varResponse[0] @@ -632,9 +613,7 @@ def translateGPT(text, history, fullPromptFlag): history = extractedTranslations[-10:] # Update history if we have a list else: # Ensure we're passing a single string to extractTranslation - extractedTranslations = extractTranslation( - "\n".join(translatedTextList), False - ) + extractedTranslations = extractTranslation("\n".join(translatedTextList), False) tList[index] = extractedTranslations finalList = combineList(tList, text) diff --git a/modules/anim.py b/modules/anim.py index fa1888e..002a489 100644 --- a/modules/anim.py +++ b/modules/anim.py @@ -81,9 +81,7 @@ def handleAnim(filename, estimate): # Print any errors on maps if len(MISMATCH) > 0: - return ( - totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET - ) + return totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET else: return totalString @@ -137,13 +135,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] == None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: @@ -173,9 +165,7 @@ def parseJSON(data, filename): totalLines = len(batches) global LOCK - with tqdm( - bar_format=BAR_FORMAT, position=POSITION, total=totalLines, leave=LEAVE - ) as pbar: + with tqdm(bar_format=BAR_FORMAT, position=POSITION, total=totalLines, leave=LEAVE) as pbar: pbar.desc = filename pbar.total = totalLines try: @@ -382,9 +372,7 @@ def batchList(input_list, batch_size): if not isinstance(batch_size, int) or batch_size <= 0: raise ValueError("batch_size must be a positive integer") - return [ - input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size) - ] + return [input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size)] def createContext(fullPromptFlag, subbedT): @@ -529,12 +517,8 @@ def translateGPT(text, history, fullPromptFlag): for index, tItem in enumerate(tList): # Before sending to translation, if we have a list of items, add the formatting if isinstance(tItem, list): - payload = "\n".join( - [f"`{item}`" for i, item in enumerate(tItem)] - ) - payload = re.sub( - r"(<)(\/Line\d+>)", r"\1>Placeholder Text<\3", payload - ) + payload = "\n".join([f"`{item}`" for i, item in enumerate(tItem)]) + payload = re.sub(r"(<)(\/Line\d+>)", r"\1>Placeholder Text<\3", payload) varResponse = subVars(payload) subbedT = varResponse[0] else: @@ -583,9 +567,7 @@ def translateGPT(text, history, fullPromptFlag): # Create History if not mismatch: - history = extractedTranslations[ - -10: - ] # Update history if we have a list + history = extractedTranslations[-10:] # Update history if we have a list else: history = text[-10:] else: diff --git a/modules/atelier.py b/modules/atelier.py index 61b389d..7bb2ddf 100644 --- a/modules/atelier.py +++ b/modules/atelier.py @@ -109,13 +109,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] is None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: @@ -144,9 +138,7 @@ def parseText(data, filename): linesList = data.readlines() totalLines = len(linesList) - with tqdm( - bar_format=BAR_FORMAT, position=POSITION, total=totalLines, leave=LEAVE - ) as pbar: + with tqdm(bar_format=BAR_FORMAT, position=POSITION, total=totalLines, leave=LEAVE) as pbar: pbar.desc = filename pbar.total = totalLines try: @@ -346,9 +338,7 @@ def translateGPT(t, history, fullPromptFlag): historyRaw = history inputTotalTokens = len(enc.encode(historyRaw)) + len(enc.encode(PROMPT)) - outputTotalTokens = ( - len(enc.encode(t)) * 2 - ) # Estimating 2x the size of the original text + outputTotalTokens = len(enc.encode(t)) * 2 # Estimating 2x the size of the original text totalTokens = [inputTotalTokens, outputTotalTokens] return (t, totalTokens) diff --git a/modules/csv.py b/modules/csv.py index f03d61c..45d8ef1 100644 --- a/modules/csv.py +++ b/modules/csv.py @@ -70,9 +70,7 @@ def handleCSV(filename, estimate): ESTIMATE = estimate if not ESTIMATE: - with open( - "translated/" + filename, "w+t", newline="", encoding="utf-8-sig" - ) as writeFile: + with open("translated/" + filename, "w+t", newline="", encoding="utf-8-sig") as writeFile: # Translate start = time.time() translatedData = openFiles(filename, writeFile) @@ -136,13 +134,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] is None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: # Fail @@ -170,9 +162,7 @@ def parseCSV(readFile, writeFile, filename): format = "" while format not in ["1", "2", "3"]: - format = input( - "\n\nSelect the CSV Format:\n\n1. Translator++\n2. Single\n3. Multiple\n" - ) + format = input("\n\nSelect the CSV Format:\n\n1. Translator++\n2. Single\n3. Multiple\n") match format: case "1": format = "1" @@ -191,9 +181,7 @@ def parseCSV(readFile, writeFile, filename): else: writer = "" - with tqdm( - bar_format=BAR_FORMAT, position=POSITION, total=totalLines, leave=LEAVE - ) as pbar: + with tqdm(bar_format=BAR_FORMAT, position=POSITION, total=totalLines, leave=LEAVE) as pbar: pbar.desc = filename pbar.total = totalLines @@ -526,9 +514,7 @@ def batchList(input_list, batch_size): if not isinstance(batch_size, int) or batch_size <= 0: raise ValueError("batch_size must be a positive integer") - return [ - input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size) - ] + return [input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size)] def createContext(fullPromptFlag, subbedT): @@ -722,13 +708,9 @@ def translateGPT(text, history, fullPromptFlag): translatedText = cleanTranslatedText(translatedText, varResponse) if isinstance(tItem, list): extractedTranslations = extractTranslation(translatedText, True) - if extractedTranslations == None or len(tItem) != len( - extractedTranslations - ): + if extractedTranslations == None or len(tItem) != len(extractedTranslations): # Mismatch. Try Again - response = translateText( - characters, system, user, history, 0.05, format - ) + response = translateText(characters, system, user, history, 0.05, format) translatedText = response.choices[0].message.content totalTokens[0] += response.usage.prompt_tokens totalTokens[1] += response.usage.completion_tokens @@ -737,17 +719,13 @@ def translateGPT(text, history, fullPromptFlag): translatedText = cleanTranslatedText(translatedText, varResponse) if isinstance(tItem, list): extractedTranslations = extractTranslation(translatedText, True) - if extractedTranslations == None or len(tItem) != len( - extractedTranslations - ): + if extractedTranslations == None or len(tItem) != len(extractedTranslations): mismatch = True # Just here for breakpoint # Set if no mismatch if mismatch == False: tList[index] = extractedTranslations - history = extractedTranslations[ - -10: - ] # Update history if we have a list + history = extractedTranslations[-10:] # Update history if we have a list else: history = text[-10:] mismatch = False diff --git a/modules/eushully.py b/modules/eushully.py index 43dbfc4..12ed04c 100644 --- a/modules/eushully.py +++ b/modules/eushully.py @@ -80,17 +80,13 @@ def handleEushully(filename, estimate): # Print any errors on maps if len(MISMATCH) > 0: - return ( - totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET - ) + return totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET else: return totalString else: try: - with open( - "translated/" + filename, "w", encoding="utf-8", errors="ignore" - ) as outFile: + with open("translated/" + filename, "w", encoding="utf-8", errors="ignore") as outFile: start = time.time() translatedData = openFiles(filename) @@ -125,13 +121,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] == None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: @@ -254,9 +244,7 @@ def translateEushully(data, pbar, filename, translatedList): # Remove speaker if speaker != "": - translatedText = re.sub( - r"^\[?(.+?)\]?\s?[|:]\s?", "", translatedText - ) + translatedText = re.sub(r"^\[?(.+?)\]?\s?[|:]\s?", "", translatedText) # Textwrap translatedText = textwrap.fill(translatedText, width=WIDTH) @@ -265,14 +253,9 @@ def translateEushully(data, pbar, filename, translatedList): # Set Data if len(translatedTextList) > 1: for j in range(len(translatedTextList)): - if any( - x in data[i] - for x in ["show-text", "set-string", "concat"] - ): + if any(x in data[i] for x in ["show-text", "set-string", "concat"]): del data[i] - data.insert( - i, f'{match.group(1)}"{translatedTextList[j]}"\n' - ) + data.insert(i, f'{match.group(1)}"{translatedTextList[j]}"\n') i += 1 if "end-text-line" not in data[i]: data.insert(i, "end-text-line 0\n") @@ -550,9 +533,7 @@ def batchList(input_list, batch_size): if not isinstance(batch_size, int) or batch_size <= 0: raise ValueError("batch_size must be a positive integer") - return [ - input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size) - ] + return [input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size)] def createContext(fullPromptFlag, subbedT): @@ -699,12 +680,8 @@ def translateGPT(text, history, fullPromptFlag): for index, tItem in enumerate(tList): # Before sending to translation, if we have a list of items, add the formatting if isinstance(tItem, list): - payload = "\n".join( - [f"`{item}`" for i, item in enumerate(tItem)] - ) - payload = re.sub( - r"(<)(\/Line\d+>)", r"\1>Placeholder Text<\3", payload - ) + payload = "\n".join([f"`{item}`" for i, item in enumerate(tItem)]) + payload = re.sub(r"(<)(\/Line\d+>)", r"\1>Placeholder Text<\3", payload) varResponse = subVars(payload) subbedT = varResponse[0] else: @@ -758,9 +735,7 @@ def translateGPT(text, history, fullPromptFlag): if PBAR is not None: PBAR.update(len(tItem)) if not mismatch: - history = extractedTranslations[ - -10: - ] # Update history if we have a list + history = extractedTranslations[-10:] # Update history if we have a list else: history = text[-10:] else: diff --git a/modules/images.py b/modules/images.py index 249d4f9..366b3e1 100644 --- a/modules/images.py +++ b/modules/images.py @@ -80,12 +80,8 @@ def handleImages(folderName, estimate): translatedList = translatedData[0][0] originalList = translatedData[0][1] dimensionsList = translatedData[0][2] - image = stringToImage( - translatedList[i], dimensionsList[i][0], dimensionsList[i][1] - ) - image.save( - rf"translated/{folderName}/{customList[0][0]}.png", quality=100 - ) + image = stringToImage(translatedList[i], dimensionsList[i][0], dimensionsList[i][1]) + image.save(rf"translated/{folderName}/{customList[0][0]}.png", quality=100) customList[0].pop(0) except Exception as e: PBAR.write(f"{translatedList[i]}: {str(e)}") @@ -152,13 +148,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] is None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: # Fail @@ -185,9 +175,7 @@ def getFontSize(text, image_width, image_height, font_path): while font_size > 0: font = ImageFont.truetype(font_path, font_size) - text_bbox = ImageDraw.Draw(Image.new("RGB", (1, 1))).textbbox( - (0, 0), text, font=font - ) + text_bbox = ImageDraw.Draw(Image.new("RGB", (1, 1))).textbbox((0, 0), text, font=font) text_width = text_bbox[2] - text_bbox[0] text_height = text_bbox[3] - text_bbox[1] @@ -198,9 +186,7 @@ def getFontSize(text, image_width, image_height, font_path): return font_size -def stringToImage( - text, width, height, font_path="fonts/TsunagiGothic.ttf", scale_factor=4 -): +def stringToImage(text, width, height, font_path="fonts/TsunagiGothic.ttf", scale_factor=4): # Increase the resolution scaled_width = int(width * scale_factor) scaled_height = int(height * scale_factor) @@ -270,9 +256,7 @@ def processImagesDir(directory_path, imageList): if ".txt" in file_name: try: - with open( - f"{directory_path}/{file_name}", "r", encoding="utf8" - ) as file: + with open(f"{directory_path}/{file_name}", "r", encoding="utf8") as file: for line in file: line = line.strip() line = line.replace(":", ":") @@ -293,9 +277,7 @@ def translateImages(imageList): totalTokens = [0, 0] # Translate GPT - response = translateGPT( - imageList[0], "Keep the Translation as brief as possible", True - ) + response = translateGPT(imageList[0], "Keep the Translation as brief as possible", True) translatedList = response[0] totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] @@ -380,9 +362,7 @@ def batchList(input_list, batch_size): if not isinstance(batch_size, int) or batch_size <= 0: raise ValueError("batch_size must be a positive integer") - return [ - input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size) - ] + return [input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size)] def createContext(fullPromptFlag, subbedT, format): @@ -615,13 +595,9 @@ def translateGPT(text, history, fullPromptFlag): translatedText = cleanTranslatedText(translatedText, varResponse) if isinstance(tItem, list): extractedTranslations = extractTranslation(translatedText, True) - if extractedTranslations == None or len(tItem) != len( - extractedTranslations - ): + if extractedTranslations == None or len(tItem) != len(extractedTranslations): # Mismatch. Try Again - response = translateText( - characters, system, user, history, 0.05, format - ) + response = translateText(characters, system, user, history, 0.05, format) translatedText = response.choices[0].message.content totalTokens[0] += response.usage.prompt_tokens totalTokens[1] += response.usage.completion_tokens @@ -630,17 +606,13 @@ def translateGPT(text, history, fullPromptFlag): translatedText = cleanTranslatedText(translatedText, varResponse) if isinstance(tItem, list): extractedTranslations = extractTranslation(translatedText, True) - if extractedTranslations == None or len(tItem) != len( - extractedTranslations - ): + if extractedTranslations == None or len(tItem) != len(extractedTranslations): mismatch = True # Just here for breakpoint # Set if no mismatch if mismatch == False: tList[index] = extractedTranslations - history = extractedTranslations[ - -10: - ] # Update history if we have a list + history = extractedTranslations[-10:] # Update history if we have a list else: history = text[-10:] mismatch = False diff --git a/modules/irissoft.py b/modules/irissoft.py index 527c352..ef89332 100644 --- a/modules/irissoft.py +++ b/modules/irissoft.py @@ -79,17 +79,13 @@ def handleIris(filename, estimate): # Print any errors on maps if len(MISMATCH) > 0: - return ( - totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET - ) + return totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET else: return totalString else: try: - with open( - "translated/" + filename, "w", encoding="cp932", errors="ignore" - ) as outFile: + with open("translated/" + filename, "w", encoding="cp932", errors="ignore") as outFile: start = time.time() translatedData = openFiles(filename) @@ -124,13 +120,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] == None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: @@ -565,9 +555,7 @@ def batchList(input_list, batch_size): if not isinstance(batch_size, int) or batch_size <= 0: raise ValueError("batch_size must be a positive integer") - return [ - input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size) - ] + return [input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size)] def createContext(fullPromptFlag, subbedT): @@ -712,12 +700,8 @@ def translateGPT(text, history, fullPromptFlag, pbar, filename): for index, tItem in enumerate(tList): # Before sending to translation, if we have a list of items, add the formatting if isinstance(tItem, list): - payload = "\n".join( - [f"`{item}`" for i, item in enumerate(tItem)] - ) - payload = re.sub( - r"(<)(\/Line\d+>)", r"\1>Placeholder Text<\3", payload - ) + payload = "\n".join([f"`{item}`" for i, item in enumerate(tItem)]) + payload = re.sub(r"(<)(\/Line\d+>)", r"\1>Placeholder Text<\3", payload) varResponse = subVars(payload) subbedT = varResponse[0] else: diff --git a/modules/javascript.py b/modules/javascript.py index 8338a98..422b56e 100644 --- a/modules/javascript.py +++ b/modules/javascript.py @@ -79,17 +79,13 @@ def handleJavascript(filename, estimate): # Print any errors on maps if len(MISMATCH) > 0: - return ( - totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET - ) + return totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET else: return totalString else: try: - with open( - "translated/" + filename, "w", encoding="utf8", errors="ignore" - ) as outFile: + with open("translated/" + filename, "w", encoding="utf8", errors="ignore") as outFile: start = time.time() translatedData = openFiles(filename) @@ -124,13 +120,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] == None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: @@ -194,9 +184,7 @@ def translateJS(data, pbar): # Remove Wordwrap [Optional] for j in range(len(modifiedStringList)): - modifiedStringList[j] = modifiedStringList[j].replace( - r"\\\\\\\\n", r" " - ) + modifiedStringList[j] = modifiedStringList[j].replace(r"\\\\\\\\n", r" ") # Translate response = translateGPT( @@ -345,9 +333,7 @@ def batchList(input_list, batch_size): if not isinstance(batch_size, int) or batch_size <= 0: raise ValueError("batch_size must be a positive integer") - return [ - input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size) - ] + return [input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size)] def createContext(fullPromptFlag, subbedT): @@ -489,12 +475,8 @@ def translateGPT(text, history, fullPromptFlag, pbar): for index, tItem in enumerate(tList): # Before sending to translation, if we have a list of items, add the formatting if isinstance(tItem, list): - payload = "\n".join( - [f"`{item}`" for i, item in enumerate(tItem)] - ) - payload = re.sub( - r"(<)(\/Line\d+>)", r"\1>Placeholder Text<\3", payload - ) + payload = "\n".join([f"`{item}`" for i, item in enumerate(tItem)]) + payload = re.sub(r"(<)(\/Line\d+>)", r"\1>Placeholder Text<\3", payload) varResponse = subVars(payload) subbedT = varResponse[0] else: diff --git a/modules/json.py b/modules/json.py index fed3316..7dbd1ce 100644 --- a/modules/json.py +++ b/modules/json.py @@ -127,13 +127,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] == None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: @@ -161,9 +155,7 @@ def parseJSON(data, filename): totalLines = len(data) global LOCK - with tqdm( - bar_format=BAR_FORMAT, position=POSITION, total=totalLines, leave=LEAVE - ) as pbar: + with tqdm(bar_format=BAR_FORMAT, position=POSITION, total=totalLines, leave=LEAVE) as pbar: pbar.desc = filename pbar.total = totalLines try: @@ -443,9 +435,7 @@ def batchList(input_list, batch_size): if not isinstance(batch_size, int) or batch_size <= 0: raise ValueError("batch_size must be a positive integer") - return [ - input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size) - ] + return [input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size)] def createContext(fullPromptFlag, subbedT): @@ -586,9 +576,7 @@ def translateGPT(text, history, fullPromptFlag): for index, tItem in enumerate(tList): # Before sending to translation, if we have a list of items, add the formatting if isinstance(tItem, list): - payload = "\n".join( - [f"`{item}`" for i, item in enumerate(tItem)] - ) + payload = "\n".join([f"`{item}`" for i, item in enumerate(tItem)]) payload = payload.replace("``", "`Placeholder Text`") varResponse = subVars(payload) subbedT = varResponse[0] @@ -626,9 +614,7 @@ def translateGPT(text, history, fullPromptFlag): history = extractedTranslations[-10:] # Update history if we have a list else: # Ensure we're passing a single string to extractTranslation - extractedTranslations = extractTranslation( - "\n".join(translatedTextList), False - ) + extractedTranslations = extractTranslation("\n".join(translatedTextList), False) tList[index] = extractedTranslations finalList = combineList(tList, text) diff --git a/modules/kansen.py b/modules/kansen.py index 178fd3f..1bc5069 100644 --- a/modules/kansen.py +++ b/modules/kansen.py @@ -79,9 +79,7 @@ def handleKansen(filename, estimate): # Print any errors on maps if len(MISMATCH) > 0: - return ( - totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET - ) + return totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET else: return totalString @@ -124,13 +122,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] == None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: @@ -174,9 +166,7 @@ def parseTyrano(readFile, filename): data = readFile.readlines() totalLines = len(data) - with tqdm( - bar_format=BAR_FORMAT, position=POSITION, total=totalLines, leave=LEAVE - ) as pbar: + with tqdm(bar_format=BAR_FORMAT, position=POSITION, total=totalLines, leave=LEAVE) as pbar: pbar.desc = filename pbar.total = totalLines @@ -557,9 +547,7 @@ def batchList(input_list, batch_size): if not isinstance(batch_size, int) or batch_size <= 0: raise ValueError("batch_size must be a positive integer") - return [ - input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size) - ] + return [input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size)] def createContext(fullPromptFlag, subbedT): @@ -684,9 +672,7 @@ def translateGPT(text, history, fullPromptFlag): for index, tItem in enumerate(tList): # Before sending to translation, if we have a list of items, add the formatting if isinstance(tItem, list): - payload = "\n".join( - [f"`{item}`" for i, item in enumerate(tItem)] - ) + payload = "\n".join([f"`{item}`" for i, item in enumerate(tItem)]) payload = payload.replace("``", "`Placeholder Text`") varResponse = subVars(payload) subbedT = varResponse[0] @@ -724,9 +710,7 @@ def translateGPT(text, history, fullPromptFlag): history = extractedTranslations[-10:] # Update history if we have a list else: # Ensure we're passing a single string to extractTranslation - extractedTranslations = extractTranslation( - "\n".join(translatedTextList), False - ) + extractedTranslations = extractTranslation("\n".join(translatedTextList), False) tList[index] = extractedTranslations finalList = combineList(tList, text) diff --git a/modules/kirikiri.py b/modules/kirikiri.py index 106d69d..250df2a 100644 --- a/modules/kirikiri.py +++ b/modules/kirikiri.py @@ -88,17 +88,13 @@ def handleKirikiri(filename, estimate): # Print any errors on maps if len(MISMATCH) > 0: - return ( - totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET - ) + return totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET else: return totalString else: try: - with open( - "translated/" + filename, "w", encoding="cp932", errors="ignore" - ) as outFile: + with open("translated/" + filename, "w", encoding="cp932", errors="ignore") as outFile: start = time.time() translatedData = openFiles(filename) @@ -138,13 +134,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] == None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: @@ -393,9 +383,7 @@ def subVars(jaString): jaString = jaString.replace("\u3000", " ") # Formatting - codeList = re.findall( - r"([\\]*(\w+)\[(\d+)\])|([\\]*(\w+)\[[\\]*\\w+\[(\d+)\]\])", jaString - ) + codeList = re.findall(r"([\\]*(\w+)\[(\d+)\])|([\\]*(\w+)\[[\\]*\\w+\[(\d+)\]\])", jaString) codeList = set(codeList) if len(codeList) != 0: for var in codeList: @@ -412,13 +400,9 @@ def resubVars(translatedText, codeList): # Formatting for var in codeList: if var[2]: - translatedText = translatedText.replace( - f"[{var[1]}Code_" + f"{var[2]}]", var[0] - ) + translatedText = translatedText.replace(f"[{var[1]}Code_" + f"{var[2]}]", var[0]) else: - translatedText = translatedText.replace( - f"[{var[4]}Code_" + f"{var[5]}]", var[3] - ) + translatedText = translatedText.replace(f"[{var[4]}Code_" + f"{var[5]}]", var[3]) return translatedText @@ -427,9 +411,7 @@ def batchList(input_list, batch_size): if not isinstance(batch_size, int) or batch_size <= 0: raise ValueError("batch_size must be a positive integer") - return [ - input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size) - ] + return [input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size)] def createContext(fullPromptFlag, subbedT, format): @@ -596,9 +578,7 @@ def translateGPT(text, history, fullPromptFlag): subbedT = varResponse[0] # Things to Check before starting translation - if not re.search( - r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", subbedT - ): + if not re.search(r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", subbedT): if PBAR is not None: PBAR.update(len(tItem)) history = tItem[-MAXHISTORY:] @@ -624,13 +604,9 @@ def translateGPT(text, history, fullPromptFlag): translatedText = cleanTranslatedText(translatedText, varResponse) if isinstance(tItem, list): extractedTranslations = extractTranslation(translatedText, True) - if extractedTranslations == None or len(tItem) != len( - extractedTranslations - ): + if extractedTranslations == None or len(tItem) != len(extractedTranslations): # Mismatch. Try Again - response = translateText( - system, user, history, 0.05, format, "gpt-4o" - ) + response = translateText(system, user, history, 0.05, format, "gpt-4o") translatedText = response.choices[0].message.content totalTokens[0] += response.usage.prompt_tokens totalTokens[1] += response.usage.completion_tokens diff --git a/modules/lune.py b/modules/lune.py index b218a17..43825b4 100644 --- a/modules/lune.py +++ b/modules/lune.py @@ -130,13 +130,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] == None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: @@ -164,9 +158,7 @@ def parseJSON(data, filename): totalLines = len(data) global LOCK - with tqdm( - bar_format=BAR_FORMAT, position=POSITION, total=totalLines, leave=LEAVE - ) as pbar: + with tqdm(bar_format=BAR_FORMAT, position=POSITION, total=totalLines, leave=LEAVE) as pbar: pbar.desc = filename pbar.total = totalLines try: @@ -385,9 +377,7 @@ def batchList(input_list, batch_size): if not isinstance(batch_size, int) or batch_size <= 0: raise ValueError("batch_size must be a positive integer") - return [ - input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size) - ] + return [input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size)] def createContext(fullPromptFlag, subbedT, format): @@ -571,9 +561,7 @@ def translateGPT(text, history, fullPromptFlag): translatedText = cleanTranslatedText(translatedText, varResponse) if isinstance(tItem, list): extractedTranslations = extractTranslation(translatedText, True) - if extractedTranslations == None or len(tItem) != len( - extractedTranslations - ): + if extractedTranslations == None or len(tItem) != len(extractedTranslations): # Mismatch. Try Again response = translateText(system, user, history, 0.05, format, "gpt-4o") translatedText = response.choices[0].message.content @@ -584,17 +572,13 @@ def translateGPT(text, history, fullPromptFlag): translatedText = cleanTranslatedText(translatedText, varResponse) if isinstance(tItem, list): extractedTranslations = extractTranslation(translatedText, True) - if extractedTranslations == None or len(tItem) != len( - extractedTranslations - ): + if extractedTranslations == None or len(tItem) != len(extractedTranslations): mismatch = True # Just here for breakpoint # Set if no mismatch if mismatch == False: tList[index] = extractedTranslations - history = extractedTranslations[ - -10: - ] # Update history if we have a list + history = extractedTranslations[-10:] # Update history if we have a list else: history = text[-10:] mismatch = False diff --git a/modules/main.py b/modules/main.py index 8c92dc2..2528ba3 100644 --- a/modules/main.py +++ b/modules/main.py @@ -102,9 +102,7 @@ to worry about being charged twice. You can simply copy the file generated in /t def main(): estimate = "" while estimate == "": - estimate = input( - "Select Translation or Cost Estimation:\n\n 1. Translate\n 2. Estimate\n" - ) + estimate = input("Select Translation or Cost Estimation:\n\n 1. Translate\n 2. Estimate\n") match estimate: case "1": estimate = False @@ -144,9 +142,7 @@ files to translate are in the /files folder and that you picked the right game e try: totalCost = future.result() except Exception as e: - tracebackLineNo = str( - traceback.extract_tb(sys.exc_info()[2])[-1].lineno - ) + tracebackLineNo = str(traceback.extract_tb(sys.exc_info()[2])[-1].lineno) tqdm.write(Fore.RED + str(e) + "|" + tracebackLineNo + Fore.RESET) if totalCost != "Fail": diff --git a/modules/nscript.py b/modules/nscript.py index a2307e6..853f9e2 100644 --- a/modules/nscript.py +++ b/modules/nscript.py @@ -89,17 +89,13 @@ def handleOnscripter(filename, estimate): # Print any errors on maps if len(MISMATCH) > 0: - return ( - totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET - ) + return totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET else: return totalString else: try: - with open( - "translated/" + filename, "w", encoding="cp932", errors="ignore" - ) as outFile: + with open("translated/" + filename, "w", encoding="cp932", errors="ignore") as outFile: start = time.time() translatedData = openFiles(filename) @@ -134,13 +130,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] == None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: @@ -292,9 +282,7 @@ def translateOnscripter(data, pbar, filename, translatedList): choiceList = re.findall(r"\"(.*?)\"", jaString) if len(choiceList) > 0: # Translate - response = translateGPT( - choiceList, "This will be a dialogue option", True - ) + response = translateGPT(choiceList, "This will be a dialogue option", True) translatedTextList = response[0] tokens[0] += response[1][0] tokens[1] += response[1][1] @@ -345,33 +333,25 @@ def fixText(translatedText): matchList = re.findall(r"([$].+?)[^\w]", translatedText) if matchList: for match in matchList: - translatedText = translatedText.replace( - match, match.translate(wide_to_ascii) - ) + 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) - ) + 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) - ) + 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) - ) + translatedText = translatedText.replace(match, match.translate(wide_to_ascii)) return translatedText @@ -534,9 +514,7 @@ def batchList(input_list, batch_size): if not isinstance(batch_size, int) or batch_size <= 0: raise ValueError("batch_size must be a positive integer") - return [ - input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size) - ] + return [input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size)] def createContext(fullPromptFlag, subbedT): @@ -757,9 +735,7 @@ def translateGPT(text, history, fullPromptFlag): # Set if no mismatch if mismatch == False: tList[index] = extractedTranslations - history = extractedTranslations[ - -10: - ] # Update history if we have a list + history = extractedTranslations[-10:] # Update history if we have a list else: history = text[-10:] mismatch = False diff --git a/modules/regex.py b/modules/regex.py index 8aa4c51..3bbf298 100644 --- a/modules/regex.py +++ b/modules/regex.py @@ -114,13 +114,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] == None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: @@ -251,9 +245,7 @@ def translateRegex(data, translatedList): stringList = None # Remove speaker - translatedText = re.sub( - r"^\[?(.+?)\]?\s?[|:]\s?", "", translatedText - ) + translatedText = re.sub(r"^\[?(.+?)\]?\s?[|:]\s?", "", translatedText) # Escape Quotes translatedText = re.sub(r'(? 0: - return ( - totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET - ) + return totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET else: return totalString else: try: - with open( - "translated/" + filename, "w", encoding="utf8", errors="ignore" - ) as outFile: + with open("translated/" + filename, "w", encoding="utf8", errors="ignore") as outFile: start = time.time() translatedData = openFiles(filename) @@ -129,13 +125,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] == None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: @@ -249,12 +239,8 @@ def translateRenpy(data, translatedList): # Remove speaker if speaker != "": - matchSpeakerList = re.findall( - r"^\[?(.+?)\]?\s?[|:]\s?", translatedText - ) - translatedText = re.sub( - r"^\[?(.+?)\]?\s?[|:]\s?", "", translatedText - ) + matchSpeakerList = re.findall(r"^\[?(.+?)\]?\s?[|:]\s?", translatedText) + translatedText = re.sub(r"^\[?(.+?)\]?\s?[|:]\s?", "", translatedText) # Escape Quotes translatedText = re.sub(r'[\\]*(")', '\\"', translatedText) @@ -277,9 +263,7 @@ def translateRenpy(data, translatedList): PBAR.refresh() # Translate - response = translateGPT( - stringList, "Reply with the English TL of the NPC Name", True - ) + response = translateGPT(stringList, "Reply with the English TL of the NPC Name", True) tokens[0] += response[1][0] tokens[1] += response[1][1] translatedList = response[0] @@ -348,9 +332,7 @@ def batchList(input_list, batch_size): if not isinstance(batch_size, int) or batch_size <= 0: raise ValueError("batch_size must be a positive integer") - return [ - input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size) - ] + return [input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size)] def createContext(fullPromptFlag, subbedT, format): @@ -519,9 +501,7 @@ def translateGPT(text, history, fullPromptFlag): subbedT = varResponse[0] # Things to Check before starting translation - if not re.search( - r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", subbedT - ): + if not re.search(r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", subbedT): if PBAR is not None: PBAR.update(len(tItem)) history = tItem[-MAXHISTORY:] @@ -547,13 +527,9 @@ def translateGPT(text, history, fullPromptFlag): translatedText = cleanTranslatedText(translatedText, varResponse) if isinstance(tItem, list): extractedTranslations = extractTranslation(translatedText, True) - if extractedTranslations == None or len(tItem) != len( - extractedTranslations - ): + if extractedTranslations == None or len(tItem) != len(extractedTranslations): # Mismatch. Try Again - response = translateText( - system, user, history, 0.05, format, "gpt-4o" - ) + response = translateText(system, user, history, 0.05, format, "gpt-4o") translatedText = response.choices[0].message.content totalTokens[0] += response.usage.prompt_tokens totalTokens[1] += response.usage.completion_tokens diff --git a/modules/rpgmakerace.py b/modules/rpgmakerace.py index 6708ef3..63ba794 100644 --- a/modules/rpgmakerace.py +++ b/modules/rpgmakerace.py @@ -228,13 +228,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] is None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: # Fail @@ -390,9 +384,7 @@ def parseTroops(data, filename): for troop in data: if troop is not None: for page in troop["pages"]: - totalLines += ( - len(page["list"]) + 1 - ) # The +1 is because each page has a name. + totalLines += len(page["list"]) + 1 # The +1 is because each page has a name. with tqdm(bar_format=BAR_FORMAT, position=POSITION, leave=LEAVE) as pbar: pbar.desc = filename @@ -522,33 +514,19 @@ def searchNames(data, pbar, context): if "Actors" in context: newContext = "Reply with only the " + LANGUAGE + " translation of the NPC name" if "Armors" in context: - newContext = ( - "Reply with only the " + LANGUAGE + " translation of the RPG equipment name" - ) + newContext = "Reply with only the " + LANGUAGE + " translation of the RPG equipment name" if "Classes" in context: - newContext = ( - "Reply with only the " + LANGUAGE + " translation of the RPG class name" - ) + newContext = "Reply with only the " + LANGUAGE + " translation of the RPG class name" if "MapInfos" in context: - newContext = ( - "Reply with only the " + LANGUAGE + " translation of the location name" - ) + newContext = "Reply with only the " + LANGUAGE + " translation of the location name" if "Enemies" in context: - newContext = ( - "Reply with only the " + LANGUAGE + " translation of the enemy NPC name" - ) + newContext = "Reply with only the " + LANGUAGE + " translation of the enemy NPC name" if "Weapons" in context: - newContext = ( - "Reply with only the " + LANGUAGE + " translation of the RPG weapon name" - ) + newContext = "Reply with only the " + LANGUAGE + " translation of the RPG weapon name" if "Items" in context: - newContext = ( - "Reply with only the " + LANGUAGE + " translation of the RPG item name" - ) + newContext = "Reply with only the " + LANGUAGE + " translation of the RPG item name" if "Skills" in context: - newContext = ( - "Reply with only the " + LANGUAGE + " translation of the RPG skill name" - ) + newContext = "Reply with only the " + LANGUAGE + " translation of the RPG skill name" # Names with open("translations.txt", "a", encoding="utf-8") as file: @@ -592,17 +570,13 @@ def searchNames(data, pbar, context): if len(nameList) < BATCHSIZE: nameList.append(data[i]["name"]) if "description" in data[i] and data[i]["description"] != "": - descriptionList.append( - data[i]["description"].replace("\n", " ") - ) + descriptionList.append(data[i]["description"].replace("\n", " ")) if "") totalTokens[0] += tokensResponse[0] totalTokens[1] += tokensResponse[1] if "" - ) + tokensResponse = translateNote(data[i], r"") totalTokens[0] += tokensResponse[0] totalTokens[1] += tokensResponse[1] if " 0 and data[i][ - f"message{number}" - ][0] in ["は", "を", "の", "に", "が"]: + if len(data[i][f"message{number}"]) > 0 and data[i][f"message{number}"][ + 0 + ] in ["は", "を", "の", "に", "が"]: msgResponse = translateGPT( "Taro" + data[i][f"message{number}"], "reply with only the gender neutral " @@ -661,9 +633,7 @@ def searchNames(data, pbar, context): + " translation of the action log. Always start the sentence with Taro. For example, Translate 'Taroを倒した!' as 'Taro was defeated!'", False, ) - data[i][f"message{number}"] = msgResponse[0].replace( - "Taro", "" - ) + data[i][f"message{number}"] = msgResponse[0].replace("Taro", "") totalTokens[0] += msgResponse[1][0] totalTokens[1] += msgResponse[1][1] number += 1 @@ -737,12 +707,8 @@ def searchNames(data, pbar, context): else: # Get Text if data[j]["name"] != "": - with open( - "translations.txt", "a", encoding="utf-8" - ) as file: - file.write( - f'{data[j]["name"]} ({translatedNameBatch[0]})\n' - ) + with open("translations.txt", "a", encoding="utf-8") as file: + file.write(f'{data[j]["name"]} ({translatedNameBatch[0]})\n') data[j]["name"] = translatedNameBatch[0] translatedNameBatch.pop(0) if data[j]["nickname"] != "": @@ -790,15 +756,10 @@ def searchNames(data, pbar, context): continue else: # Get Text - file.write( - f'{data[j]['name']} ({translatedNameBatch[0]})\n' - ) + file.write(f'{data[j]['name']} ({translatedNameBatch[0]})\n') data[j]["name"] = translatedNameBatch[0] translatedNameBatch.pop(0) - if ( - "description" in data[j] - and data[j]["description"] != "" - ): + if "description" in data[j] and data[j]["description"] != "": data[j]["description"] = textwrap.fill( translatedDescriptionBatch[0], LISTWIDTH ) @@ -828,12 +789,8 @@ def searchNames(data, pbar, context): j += 1 continue else: - with open( - "translations.txt", "a", encoding="utf-8" - ) as file: - file.write( - f'{data[j]["name"]} ({translatedNameBatch[0]})\n' - ) + with open("translations.txt", "a", encoding="utf-8") as file: + file.write(f'{data[j]["name"]} ({translatedNameBatch[0]})\n') # Get Text data[j]["name"] = translatedNameBatch[0] translatedNameBatch.pop(0) @@ -921,11 +878,7 @@ def searchCodes(page, pbar, jobList, filename): nametag = "" ## Event Code: 401 Show Text - if ( - "c" in codeList[i] - and codeList[i]["c"] in [401, 405, -1] - and (CODE401 or CODE405) - ): + if "c" in codeList[i] and codeList[i]["c"] in [401, 405, -1] and (CODE401 or CODE405): # Save Code and starting index (j) code = codeList[i]["c"] j = i @@ -1002,9 +955,7 @@ def searchCodes(page, pbar, jobList, filename): and len(codeList[i + 1]["p"]) > 0 and len(codeList[i + 1]["p"][0]) > 0 ): - if codeList[i + 1]["p"] != "" and codeList[i + 1]["p"][ - 0 - ].strip()[0] in [ + if codeList[i + 1]["p"] != "" and codeList[i + 1]["p"][0].strip()[0] in [ "「", '"', "(", @@ -1022,9 +973,7 @@ def searchCodes(page, pbar, jobList, filename): totalTokens[1] += response[1][1] # Set Data - codeList[i]["p"][0] = nametag + jaString.replace( - speakerList[0], speaker - ) + codeList[i]["p"][0] = nametag + jaString.replace(speakerList[0], speaker) nametag = "" # Iterate to next string @@ -1136,9 +1085,7 @@ def searchCodes(page, pbar, jobList, filename): ### Remove format codes # Furigana - rcodeMatch = re.findall( - r"([\\]+[r][b]?\[.*?,(.*?)\])", finalJAString - ) + rcodeMatch = re.findall(r"([\\]+[r][b]?\[.*?,(.*?)\])", finalJAString) if len(rcodeMatch) > 0: for match in rcodeMatch: finalJAString = finalJAString.replace(match[0], match[1]) @@ -1219,13 +1166,9 @@ def searchCodes(page, pbar, jobList, filename): finalJAString = finalJAString.replace("
", " ") if FIXTEXTWRAP is True and "_ABL" in nametag: - translatedText = textwrap.fill( - translatedText, width=100 - ) + translatedText = textwrap.fill(translatedText, width=100) elif FIXTEXTWRAP is True: - translatedText = textwrap.fill( - translatedText, width=WIDTH - ) + translatedText = textwrap.fill(translatedText, width=WIDTH) # BR Flag if BRFLAG is True: @@ -1236,9 +1179,7 @@ def searchCodes(page, pbar, jobList, filename): if CLFlag: translatedText = "\\ac " + translatedText translatedText = translatedText.replace("\n", "\n\\ac ") - translatedText = re.sub( - r"[\\]+?ac\s+", r"\\ac ", translatedText - ) + translatedText = re.sub(r"[\\]+?ac\s+", r"\\ac ", translatedText) CLFlag = False # Nametag @@ -1322,9 +1263,7 @@ def searchCodes(page, pbar, jobList, filename): translatedText = translatedText.replace("\n", "\\n") # Set - codeList[i]["p"][4] = jaString.replace( - finalJAString, translatedText - ) + codeList[i]["p"][4] = jaString.replace(finalJAString, translatedText) list122.pop(0) ## Event Code: 357 [Picture Text] [Optional] @@ -1363,9 +1302,7 @@ def searchCodes(page, pbar, jobList, filename): # Replace Strings for j in range(len(matchList)): - translatedText = translatedText.replace( - matchList[j], response[0][j] - ) + translatedText = translatedText.replace(matchList[j], response[0][j]) # Set Data codeList[i]["p"][3]["choices"] = translatedText @@ -1524,9 +1461,7 @@ def searchCodes(page, pbar, jobList, filename): if len(list357) > 0: # Grab and Replace translatedText = list357[0] - translatedText = jaString.replace( - jaString, translatedText - ) + translatedText = jaString.replace(jaString, translatedText) # Remove characters that may break scripts charList = ['"', "\\n"] @@ -1539,7 +1474,9 @@ def searchCodes(page, pbar, jobList, filename): # Center Text if acExist: - translatedText = f'\\ac {translatedText.replace('\n', '\n\\ac ')}' + translatedText = ( + f'\\ac {translatedText.replace('\n', '\n\\ac ')}' + ) # Set codeList[i]["p"][3][argVar] = translatedText @@ -1560,23 +1497,15 @@ def searchCodes(page, pbar, jobList, filename): continue # If there isn't any Japanese in the text just skip - if not re.search( - r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", jaString - ): + if not re.search(r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", jaString): i += 1 continue # Remove outside text - startString = re.search( - r"^[^一-龠ぁ-ゔァ-ヴー\<\>【】\\]+", jaString - ) + startString = re.search(r"^[^一-龠ぁ-ゔァ-ヴー\<\>【】\\]+", jaString) jaString = re.sub(r"^[^一-龠ぁ-ゔァ-ヴー\<\>【】\\]+", "", jaString) - endString = re.search( - r"[^一-龠ぁ-ゔァ-ヴー\<\>【】。!?\\]+$", jaString - ) - jaString = re.sub( - r"[^一-龠ぁ-ゔァ-ヴー\<\>【】。!?\\]+$", "", jaString - ) + endString = re.search(r"[^一-龠ぁ-ゔァ-ヴー\<\>【】。!?\\]+$", jaString) + jaString = re.sub(r"[^一-龠ぁ-ゔァ-ヴー\<\>【】。!?\\]+$", "", jaString) if startString is None: startString = "" else: @@ -1632,31 +1561,19 @@ def searchCodes(page, pbar, jobList, filename): continue # Force Speaker using var - if ( - "\\ap[1左]" in jaString.lower() - or "\\ap[1右]" in jaString.lower() - ): + if "\\ap[1左]" in jaString.lower() or "\\ap[1右]" in jaString.lower(): speaker = "Cecily" i += 1 continue - elif ( - "\\ap[2左]" in jaString.lower() - or "\\ap[2右]" in jaString.lower() - ): + elif "\\ap[2左]" in jaString.lower() or "\\ap[2右]" in jaString.lower(): speaker = "Amelia" i += 1 continue - elif ( - "\\ap[3左]" in jaString.lower() - or "\\ap[3右]" in jaString.lower() - ): + elif "\\ap[3左]" in jaString.lower() or "\\ap[3右]" in jaString.lower(): speaker = "Henry" i += 1 continue - elif ( - "\\ap[4左]" in jaString.lower() - or "\\ap[4右]" in jaString.lower() - ): + elif "\\ap[4左]" in jaString.lower() or "\\ap[4右]" in jaString.lower(): speaker = "Oswald" i += 1 continue @@ -1720,9 +1637,7 @@ def searchCodes(page, pbar, jobList, filename): jaString = codeList[i]["p"][0] # If there isn't any Japanese in the text just skip - if not re.search( - r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", jaString - ): + if not re.search(r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", jaString): i += 1 continue @@ -1741,9 +1656,7 @@ def searchCodes(page, pbar, jobList, filename): match = match.replace("\n", " ") response = translateGPT( match, - "Reply with the " - + LANGUAGE - + " translation of the achievement title.", + "Reply with the " + LANGUAGE + " translation of the achievement title.", False, ) translatedText = response[0] @@ -1769,9 +1682,7 @@ def searchCodes(page, pbar, jobList, filename): jaString = codeList[i]["p"][0] # If there isn't any Japanese in the text just skip - if not re.search( - r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", jaString - ): + if not re.search(r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", jaString): i += 1 continue @@ -1805,9 +1716,7 @@ def searchCodes(page, pbar, jobList, filename): translatedText = translatedText.replace(char, "") translatedText = translatedText.replace('"', '"') translatedText = translatedText.replace(" ", "_") - translatedText = jaString.replace( - match.group(1), translatedText - ) + translatedText = jaString.replace(match.group(1), translatedText) # Set Data codeList[i]["p"][0] = translatedText @@ -1824,9 +1733,7 @@ def searchCodes(page, pbar, jobList, filename): # Translate response = translateGPT( matchList[0], - "Reply with the " - + LANGUAGE - + " translation of the NPC name.", + "Reply with the " + LANGUAGE + " translation of the NPC name.", False, ) translatedText = response[0] @@ -1908,9 +1815,7 @@ def searchCodes(page, pbar, jobList, filename): codeList[i]["p"][0] = translatedText if "LL_InfoPopupWIndowMV" in jaString: - matchList = re.findall( - r"LL_InfoPopupWIndowMV\sshowWindow\s(.+?) .+", jaString - ) + matchList = re.findall(r"LL_InfoPopupWIndowMV\sshowWindow\s(.+?) .+", jaString) if len(matchList) > 0: # Translate text = matchList[0] @@ -1927,9 +1832,7 @@ def searchCodes(page, pbar, jobList, filename): codeList[i]["p"][0] = translatedText if "OriginMenuStatus SetParam" in jaString: - matchList = re.findall( - r"OriginMenuStatus\sSetParam\sparam[\d]\s(.*)", jaString - ) + matchList = re.findall(r"OriginMenuStatus\sSetParam\sparam[\d]\s(.*)", jaString) if len(matchList) > 0: # Translate text = matchList[0] @@ -1948,9 +1851,7 @@ def searchCodes(page, pbar, jobList, filename): # LL_GalgeChoiceWindowMV Message if "LL_GalgeChoiceWindowMV setMessageText" in jaString: ### Message Text First - match = re.search( - r"LL_GalgeChoiceWindowMV setMessageText (.+)", jaString - ) + match = re.search(r"LL_GalgeChoiceWindowMV setMessageText (.+)", jaString) if match: jaString = match.group(1) @@ -1966,16 +1867,12 @@ def searchCodes(page, pbar, jobList, filename): translatedText = translatedText.replace(" ", "_") # Replace and Set - translatedText = match.group(0).replace( - match.group(1), translatedText - ) + translatedText = match.group(0).replace(match.group(1), translatedText) codeList[i]["p"][0] = translatedText # LL_GalgeChoiceWindowMV Choices if "LL_GalgeChoiceWindowMV setChoices": - match = re.search( - r"LL_GalgeChoiceWindowMV setChoices (.+)", jaString - ) + match = re.search(r"LL_GalgeChoiceWindowMV setChoices (.+)", jaString) if match: jaString = match.group(1) choiceList = jaString.split(",") @@ -1995,9 +1892,7 @@ def searchCodes(page, pbar, jobList, filename): # Replace Strings for j in range(len(choiceListTL)): choiceListTL[j] = choiceListTL[j].replace(" ", "_") - translatedText = translatedText.replace( - choiceList[j], choiceListTL[j] - ) + translatedText = translatedText.replace(choiceList[j], choiceListTL[j]) # Set Data codeList[i]["p"][0] = translatedText @@ -2039,9 +1934,7 @@ def searchCodes(page, pbar, jobList, filename): totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] else: - response = translateGPT( - choiceList, "This will be a dialogue option", True - ) + response = translateGPT(choiceList, "This will be a dialogue option", True) translatedTextList = response[0] totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] @@ -2056,9 +1949,7 @@ def searchCodes(page, pbar, jobList, filename): totalTokens[1] += response[1][1] if translatedText != "": translatedText = ( - varList[choice] - + translatedText[0].upper() - + translatedText[1:] + varList[choice] + translatedText[0].upper() + translatedText[1:] ) else: translatedText = varList[choice] + translatedText @@ -2120,9 +2011,7 @@ def searchCodes(page, pbar, jobList, filename): continue # If there isn't any Japanese in the text just skip - if not re.search( - r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", jaString - ): + if not re.search(r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", jaString): i += 1 continue @@ -2166,9 +2055,7 @@ def searchCodes(page, pbar, jobList, filename): # 122 if len(list122) > 0: - response = translateGPT( - list122, "Keep you translation as brief as possible", True - ) + response = translateGPT(list122, "Keep you translation as brief as possible", True) list122TL = response[0] totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] @@ -2568,9 +2455,7 @@ def subVars(jaString): jaString = jaString.replace("\u3000", " ") # Formatting - codeList = re.findall( - r"([\\]*(\w+)\[(\d+)\])|([\\]*(\w+)\[[\\]*\\w+\[(\d+)\]\])", jaString - ) + codeList = re.findall(r"([\\]*(\w+)\[(\d+)\])|([\\]*(\w+)\[[\\]*\\w+\[(\d+)\]\])", jaString) codeList = set(codeList) if len(codeList) != 0: for var in codeList: @@ -2587,13 +2472,9 @@ def resubVars(translatedText, codeList): # Formatting for var in codeList: if var[2]: - translatedText = translatedText.replace( - f"[{var[1]}Code_" + f"{var[2]}]", var[0] - ) + translatedText = translatedText.replace(f"[{var[1]}Code_" + f"{var[2]}]", var[0]) else: - translatedText = translatedText.replace( - f"[{var[4]}Code_" + f"{var[5]}]", var[3] - ) + translatedText = translatedText.replace(f"[{var[4]}Code_" + f"{var[5]}]", var[3]) return translatedText @@ -2602,9 +2483,7 @@ def batchList(input_list, batch_size): if not isinstance(batch_size, int) or batch_size <= 0: raise ValueError("batch_size must be a positive integer") - return [ - input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size) - ] + return [input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size)] def createContext(fullPromptFlag, subbedT, format): @@ -2771,9 +2650,7 @@ def translateGPT(text, history, fullPromptFlag): subbedT = varResponse[0] # Things to Check before starting translation - if not re.search( - r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", subbedT - ): + if not re.search(r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", subbedT): if PBAR is not None: PBAR.update(len(tItem)) history = tItem[-MAXHISTORY:] @@ -2799,13 +2676,9 @@ def translateGPT(text, history, fullPromptFlag): translatedText = cleanTranslatedText(translatedText, varResponse) if isinstance(tItem, list): extractedTranslations = extractTranslation(translatedText, True) - if extractedTranslations == None or len(tItem) != len( - extractedTranslations - ): + if extractedTranslations == None or len(tItem) != len(extractedTranslations): # Mismatch. Try Again - response = translateText( - system, user, history, 0.05, format, "gpt-4o" - ) + response = translateText(system, user, history, 0.05, format, "gpt-4o") translatedText = response.choices[0].message.content totalTokens[0] += response.usage.prompt_tokens totalTokens[1] += response.usage.completion_tokens diff --git a/modules/rpgmakermvmz.py b/modules/rpgmakermvmz.py index c7ccb8a..1d3f0c8 100644 --- a/modules/rpgmakermvmz.py +++ b/modules/rpgmakermvmz.py @@ -206,13 +206,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] is None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: # Fail @@ -264,9 +258,7 @@ def parseMap(data, filename): if event is not None: # This translates ID of events. (May break the game) if ".*" - ) + response = translateNoteOmitSpace(event, r".*") totalTokens[0] += response[0] totalTokens[1] += response[1] if "") totalTokens[0] += tokensResponse[0] totalTokens[1] += tokensResponse[1] if "" - ) + tokensResponse = translateNote(data[i], r"") totalTokens[0] += tokensResponse[0] totalTokens[1] += tokensResponse[1] if " 0 and data[i][ - f"message{number}" - ][0] in ["は", "を", "の", "に", "が"]: + if len(data[i][f"message{number}"]) > 0 and data[i][f"message{number}"][ + 0 + ] in ["は", "を", "の", "に", "が"]: msgResponse = translateGPT( "Taro" + data[i][f"message{number}"], "reply with only the gender neutral " @@ -658,9 +628,7 @@ def searchNames(data, pbar, context): + " translation of the action log. Always start the sentence with Taro. For example, Translate 'Taroを倒した!' as 'Taro was defeated!'", False, ) - data[i][f"message{number}"] = msgResponse[0].replace( - "Taro", "" - ) + data[i][f"message{number}"] = msgResponse[0].replace("Taro", "") totalTokens[0] += msgResponse[1][0] totalTokens[1] += msgResponse[1][1] number += 1 @@ -734,12 +702,8 @@ def searchNames(data, pbar, context): else: # Get Text if data[j]["name"] != "": - with open( - "translations.txt", "a", encoding="utf-8" - ) as file: - file.write( - f'{data[j]["name"]} ({translatedNameBatch[0]})\n' - ) + with open("translations.txt", "a", encoding="utf-8") as file: + file.write(f'{data[j]["name"]} ({translatedNameBatch[0]})\n') data[j]["name"] = translatedNameBatch[0] translatedNameBatch.pop(0) if data[j]["nickname"] != "": @@ -787,15 +751,10 @@ def searchNames(data, pbar, context): continue else: # Get Text - file.write( - f'{data[j]['name']} ({translatedNameBatch[0]})\n' - ) + file.write(f'{data[j]['name']} ({translatedNameBatch[0]})\n') data[j]["name"] = translatedNameBatch[0] translatedNameBatch.pop(0) - if ( - "description" in data[j] - and data[j]["description"] != "" - ): + if "description" in data[j] and data[j]["description"] != "": data[j]["description"] = textwrap.fill( translatedDescriptionBatch[0], LISTWIDTH ) @@ -825,12 +784,8 @@ def searchNames(data, pbar, context): j += 1 continue else: - with open( - "translations.txt", "a", encoding="utf-8" - ) as file: - file.write( - f'{data[j]["name"]} ({translatedNameBatch[0]})\n' - ) + with open("translations.txt", "a", encoding="utf-8") as file: + file.write(f'{data[j]["name"]} ({translatedNameBatch[0]})\n') # Get Text data[j]["name"] = translatedNameBatch[0] translatedNameBatch.pop(0) @@ -939,9 +894,7 @@ def searchCodes(page, pbar, jobList, filename): # Validate Japanese Text if ( - not re.search( - r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", jaString - ) + not re.search(r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", jaString) and IGNORETLTEXT ): i += 1 @@ -1005,9 +958,9 @@ def searchCodes(page, pbar, jobList, filename): and len(codeList[i + 1]["parameters"]) > 0 and len(codeList[i + 1]["parameters"][0]) > 0 ): - if codeList[i + 1]["parameters"] != "" and codeList[i + 1][ - "parameters" - ][0].strip()[0] in [ + if codeList[i + 1]["parameters"] != "" and codeList[i + 1]["parameters"][ + 0 + ].strip()[0] in [ "「", '"', "(", @@ -1106,9 +1059,7 @@ def searchCodes(page, pbar, jobList, filename): ### Remove format codes # Furigana - rcodeMatch = re.findall( - r"([\\]+[r][b]?\[.*?,(.*?)\])", finalJAString - ) + rcodeMatch = re.findall(r"([\\]+[r][b]?\[.*?,(.*?)\])", finalJAString) if len(rcodeMatch) > 0: for match in rcodeMatch: finalJAString = finalJAString.replace(match[0], match[1]) @@ -1196,13 +1147,9 @@ def searchCodes(page, pbar, jobList, filename): finalJAString = finalJAString.replace("
", " ") if FIXTEXTWRAP is True and "_ABL" in nametag: - translatedText = textwrap.fill( - translatedText, width=100 - ) + translatedText = textwrap.fill(translatedText, width=100) elif FIXTEXTWRAP is True: - translatedText = textwrap.fill( - translatedText, width=WIDTH - ) + translatedText = textwrap.fill(translatedText, width=WIDTH) # BR Flag if BRFLAG is True: @@ -1211,18 +1158,14 @@ def searchCodes(page, pbar, jobList, filename): # px if "\\px[200]" in nametag: translatedText = translatedText.replace("\\px[200]", "") - translatedText = translatedText.replace( - "\n", "\n\\px[200]" - ) + translatedText = translatedText.replace("\n", "\n\\px[200]") ### Add Var Strings # CL Flag if CLFlag: translatedText = "\\ac " + translatedText translatedText = translatedText.replace("\n", "\n\\ac ") - translatedText = re.sub( - r"[\\]+?ac\s+", r"\\ac ", translatedText - ) + translatedText = re.sub(r"[\\]+?ac\s+", r"\\ac ", translatedText) CLFlag = False # Nametag @@ -1343,9 +1286,7 @@ def searchCodes(page, pbar, jobList, filename): # Replace Strings for j in range(len(matchList)): - translatedText = translatedText.replace( - matchList[j], response[0][j] - ) + translatedText = translatedText.replace(matchList[j], response[0][j]) # Set Data codeList[i]["parameters"][3]["choices"] = translatedText @@ -1505,9 +1446,7 @@ def searchCodes(page, pbar, jobList, filename): if len(list357) > 0: # Grab and Replace translatedText = list357[0] - translatedText = jaString.replace( - jaString, translatedText - ) + translatedText = jaString.replace(jaString, translatedText) # Remove characters that may break scripts charList = ['"', "\\n"] @@ -1520,7 +1459,9 @@ def searchCodes(page, pbar, jobList, filename): # Center Text if acExist: - translatedText = f'\\ac {translatedText.replace('\n', '\n\\ac ')}' + translatedText = ( + f'\\ac {translatedText.replace('\n', '\n\\ac ')}' + ) # Check and Set Font if "fontSize" in codeList[i]["parameters"][3]: @@ -1545,23 +1486,15 @@ def searchCodes(page, pbar, jobList, filename): continue # If there isn't any Japanese in the text just skip - if not re.search( - r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", jaString - ): + if not re.search(r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", jaString): i += 1 continue # Remove outside text - startString = re.search( - r"^[^一-龠ぁ-ゔァ-ヴー\<\>【】\\]+", jaString - ) + startString = re.search(r"^[^一-龠ぁ-ゔァ-ヴー\<\>【】\\]+", jaString) jaString = re.sub(r"^[^一-龠ぁ-ゔァ-ヴー\<\>【】\\]+", "", jaString) - endString = re.search( - r"[^一-龠ぁ-ゔァ-ヴー\<\>【】。!?\\]+$", jaString - ) - jaString = re.sub( - r"[^一-龠ぁ-ゔァ-ヴー\<\>【】。!?\\]+$", "", jaString - ) + endString = re.search(r"[^一-龠ぁ-ゔァ-ヴー\<\>【】。!?\\]+$", jaString) + jaString = re.sub(r"[^一-龠ぁ-ゔァ-ヴー\<\>【】。!?\\]+$", "", jaString) if startString is None: startString = "" else: @@ -1617,31 +1550,19 @@ def searchCodes(page, pbar, jobList, filename): continue # Force Speaker using var - if ( - "\\ap[1左]" in jaString.lower() - or "\\ap[1右]" in jaString.lower() - ): + if "\\ap[1左]" in jaString.lower() or "\\ap[1右]" in jaString.lower(): speaker = "Cecily" i += 1 continue - elif ( - "\\ap[2左]" in jaString.lower() - or "\\ap[2右]" in jaString.lower() - ): + elif "\\ap[2左]" in jaString.lower() or "\\ap[2右]" in jaString.lower(): speaker = "Amelia" i += 1 continue - elif ( - "\\ap[3左]" in jaString.lower() - or "\\ap[3右]" in jaString.lower() - ): + elif "\\ap[3左]" in jaString.lower() or "\\ap[3右]" in jaString.lower(): speaker = "Henry" i += 1 continue - elif ( - "\\ap[4左]" in jaString.lower() - or "\\ap[4右]" in jaString.lower() - ): + elif "\\ap[4左]" in jaString.lower() or "\\ap[4右]" in jaString.lower(): speaker = "Oswald" i += 1 continue @@ -1695,23 +1616,17 @@ def searchCodes(page, pbar, jobList, filename): translatedText = translatedText.replace("'", "\\'") # Set - codeList[i]["parameters"][0] = codeList[i]["parameters"][ - 0 - ].replace(finalJAString, translatedText) + codeList[i]["parameters"][0] = codeList[i]["parameters"][0].replace( + finalJAString, translatedText + ) list355655.pop(0) ## Event Code: 408 (Script) - if ( - "code" in codeList[i] - and (codeList[i]["code"] == 408) - and CODE408 is True - ): + if "code" in codeList[i] and (codeList[i]["code"] == 408) and CODE408 is True: jaString = codeList[i]["parameters"][0] # If there isn't any Japanese in the text just skip - if not re.search( - r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", jaString - ): + if not re.search(r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", jaString): i += 1 continue @@ -1730,9 +1645,7 @@ def searchCodes(page, pbar, jobList, filename): match = match.replace("\n", " ") response = translateGPT( match, - "Reply with the " - + LANGUAGE - + " translation of the achievement title.", + "Reply with the " + LANGUAGE + " translation of the achievement title.", False, ) translatedText = response[0] @@ -1754,17 +1667,11 @@ def searchCodes(page, pbar, jobList, filename): codeList[i]["parameters"][0] = translatedText ## Event Code: 108 (Script) - if ( - "code" in codeList[i] - and (codeList[i]["code"] == 108) - and CODE108 is True - ): + if "code" in codeList[i] and (codeList[i]["code"] == 108) and CODE108 is True: jaString = codeList[i]["parameters"][0] # If there isn't any Japanese in the text just skip - if not re.search( - r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", jaString - ): + if not re.search(r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", jaString): i += 1 continue @@ -1798,9 +1705,7 @@ def searchCodes(page, pbar, jobList, filename): translatedText = translatedText.replace(char, "") translatedText = translatedText.replace('"', '"') translatedText = translatedText.replace(" ", "_") - translatedText = jaString.replace( - match.group(1), translatedText - ) + translatedText = jaString.replace(match.group(1), translatedText) # Set Data codeList[i]["parameters"][0] = translatedText @@ -1817,9 +1722,7 @@ def searchCodes(page, pbar, jobList, filename): # Translate response = translateGPT( matchList[0], - "Reply with the " - + LANGUAGE - + " translation of the NPC name.", + "Reply with the " + LANGUAGE + " translation of the NPC name.", False, ) translatedText = response[0] @@ -1829,9 +1732,7 @@ def searchCodes(page, pbar, jobList, filename): # Set Text speaker = translatedText speaker = speaker.replace(" ", " ") - codeList[i]["parameters"][0] = jaString.replace( - matchList[0], speaker - ) + codeList[i]["parameters"][0] = jaString.replace(matchList[0], speaker) i += 1 continue @@ -1903,9 +1804,7 @@ def searchCodes(page, pbar, jobList, filename): codeList[i]["parameters"][0] = translatedText if "LL_InfoPopupWIndowMV" in jaString: - matchList = re.findall( - r"LL_InfoPopupWIndowMV\sshowWindow\s(.+?) .+", jaString - ) + matchList = re.findall(r"LL_InfoPopupWIndowMV\sshowWindow\s(.+?) .+", jaString) if len(matchList) > 0: # Translate text = matchList[0] @@ -1922,9 +1821,7 @@ def searchCodes(page, pbar, jobList, filename): codeList[i]["parameters"][0] = translatedText if "OriginMenuStatus SetParam" in jaString: - matchList = re.findall( - r"OriginMenuStatus\sSetParam\sparam[\d]\s(.*)", jaString - ) + matchList = re.findall(r"OriginMenuStatus\sSetParam\sparam[\d]\s(.*)", jaString) if len(matchList) > 0: # Translate text = matchList[0] @@ -1943,9 +1840,7 @@ def searchCodes(page, pbar, jobList, filename): # LL_GalgeChoiceWindowMV Message if "LL_GalgeChoiceWindowMV setMessageText" in jaString: ### Message Text First - match = re.search( - r"LL_GalgeChoiceWindowMV setMessageText (.+)", jaString - ) + match = re.search(r"LL_GalgeChoiceWindowMV setMessageText (.+)", jaString) if match: jaString = match.group(1) @@ -1961,16 +1856,12 @@ def searchCodes(page, pbar, jobList, filename): translatedText = translatedText.replace(" ", "_") # Replace and Set - translatedText = match.group(0).replace( - match.group(1), translatedText - ) + translatedText = match.group(0).replace(match.group(1), translatedText) codeList[i]["parameters"][0] = translatedText # LL_GalgeChoiceWindowMV Choices if "LL_GalgeChoiceWindowMV setChoices": - match = re.search( - r"LL_GalgeChoiceWindowMV setChoices (.+)", jaString - ) + match = re.search(r"LL_GalgeChoiceWindowMV setChoices (.+)", jaString) if match: jaString = match.group(1) choiceList = jaString.split(",") @@ -1990,9 +1881,7 @@ def searchCodes(page, pbar, jobList, filename): # Replace Strings for j in range(len(choiceListTL)): choiceListTL[j] = choiceListTL[j].replace(" ", "_") - translatedText = translatedText.replace( - choiceList[j], choiceListTL[j] - ) + translatedText = translatedText.replace(choiceList[j], choiceListTL[j]) # Set Data codeList[i]["parameters"][0] = translatedText @@ -2034,9 +1923,7 @@ def searchCodes(page, pbar, jobList, filename): totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] else: - response = translateGPT( - choiceList, "This will be a dialogue option", True - ) + response = translateGPT(choiceList, "This will be a dialogue option", True) translatedTextList = response[0] totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] @@ -2051,9 +1938,7 @@ def searchCodes(page, pbar, jobList, filename): totalTokens[1] += response[1][1] if translatedText != "": translatedText = ( - varList[choice] - + translatedText[0].upper() - + translatedText[1:] + varList[choice] + translatedText[0].upper() + translatedText[1:] ) else: translatedText = varList[choice] + translatedText @@ -2115,9 +2000,7 @@ def searchCodes(page, pbar, jobList, filename): continue # If there isn't any Japanese in the text just skip - if not re.search( - r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", jaString - ): + if not re.search(r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", jaString): i += 1 continue @@ -2164,9 +2047,7 @@ def searchCodes(page, pbar, jobList, filename): # 122 if len(list122) > 0: - response = translateGPT( - list122, "Keep you translation as brief as possible", True - ) + response = translateGPT(list122, "Keep you translation as brief as possible", True) list122TL = response[0] totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] @@ -2563,9 +2444,7 @@ def batchList(input_list, batch_size): if not isinstance(batch_size, int) or batch_size <= 0: raise ValueError("batch_size must be a positive integer") - return [ - input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size) - ] + return [input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size)] def createContext(fullPromptFlag, subbedT, format): @@ -2734,9 +2613,7 @@ def translateGPT(text, history, fullPromptFlag): subbedT = varResponse[0] # Things to Check before starting translation - if not re.search( - r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", subbedT - ): + if not re.search(r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", subbedT): if PBAR is not None: PBAR.update(len(tItem)) history = tItem[-MAXHISTORY:] @@ -2762,13 +2639,9 @@ def translateGPT(text, history, fullPromptFlag): translatedText = cleanTranslatedText(translatedText, varResponse) if isinstance(tItem, list): extractedTranslations = extractTranslation(translatedText, True) - if extractedTranslations == None or len(tItem) != len( - extractedTranslations - ): + if extractedTranslations == None or len(tItem) != len(extractedTranslations): # Mismatch. Try Again - response = translateText( - system, user, history, 0.05, format, "gpt-4o" - ) + response = translateText(system, user, history, 0.05, format, "gpt-4o") translatedText = response.choices[0].message.content totalTokens[0] += response.usage.prompt_tokens totalTokens[1] += response.usage.completion_tokens diff --git a/modules/rpgmakerplugin.py b/modules/rpgmakerplugin.py index f8af2cd..29e02e3 100644 --- a/modules/rpgmakerplugin.py +++ b/modules/rpgmakerplugin.py @@ -81,17 +81,13 @@ def handlePlugin(filename, estimate): # Print any errors on maps if len(MISMATCH) > 0: - return ( - totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET - ) + return totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET else: return totalString else: try: - with open( - "translated/" + filename, "w", encoding="utf_8", errors="ignore" - ) as outFile: + with open("translated/" + filename, "w", encoding="utf_8", errors="ignore") as outFile: start = time.time() translatedData = openFiles(filename) @@ -126,13 +122,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] == None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: @@ -439,9 +429,7 @@ def batchList(input_list, batch_size): if not isinstance(batch_size, int) or batch_size <= 0: raise ValueError("batch_size must be a positive integer") - return [ - input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size) - ] + return [input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size)] def createContext(fullPromptFlag, subbedT): @@ -641,13 +629,9 @@ def translateGPT(text, history, fullPromptFlag): translatedText = cleanTranslatedText(translatedText, varResponse) if isinstance(tItem, list): extractedTranslations = extractTranslation(translatedText, True) - if extractedTranslations == None or len(tItem) != len( - extractedTranslations - ): + if extractedTranslations == None or len(tItem) != len(extractedTranslations): # Mismatch. Try Again - response = translateText( - characters, system, user, history, 0.05, format - ) + response = translateText(characters, system, user, history, 0.05, format) translatedText = response.choices[0].message.content totalTokens[0] += response.usage.prompt_tokens totalTokens[1] += response.usage.completion_tokens @@ -656,17 +640,13 @@ def translateGPT(text, history, fullPromptFlag): translatedText = cleanTranslatedText(translatedText, varResponse) if isinstance(tItem, list): extractedTranslations = extractTranslation(translatedText, True) - if extractedTranslations == None or len(tItem) != len( - extractedTranslations - ): + if extractedTranslations == None or len(tItem) != len(extractedTranslations): mismatch = True # Just here for breakpoint # Set if no mismatch if mismatch == False: tList[index] = extractedTranslations - history = extractedTranslations[ - -10: - ] # Update history if we have a list + history = extractedTranslations[-10:] # Update history if we have a list else: history = text[-10:] mismatch = False diff --git a/modules/sakuranbo.py b/modules/sakuranbo.py index b0e4c29..a9c2bc3 100644 --- a/modules/sakuranbo.py +++ b/modules/sakuranbo.py @@ -108,13 +108,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] is None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: @@ -157,9 +151,7 @@ def parseTyrano(readFile, filename): data = readFile.readlines() totalLines = len(data) - with tqdm( - bar_format=BAR_FORMAT, position=POSITION, total=totalLines, leave=LEAVE - ) as pbar: + with tqdm(bar_format=BAR_FORMAT, position=POSITION, total=totalLines, leave=LEAVE) as pbar: pbar.desc = filename pbar.total = totalLines @@ -300,9 +292,7 @@ def translateTyrano(data, pbar): translatedText = response[0] textHistory.append('"' + translatedText + '"') else: - response = translateGPT( - speaker + ": " + finalJAString, textHistory, True - ) + response = translateGPT(speaker + ": " + finalJAString, textHistory, True) tokens[0] += response[1][0] tokens[1] += response[1][1] translatedText = response[0] @@ -375,9 +365,7 @@ def translateTyrano(data, pbar): translatedText = response[0] textHistory.append('"' + translatedText + '"') else: - response = translateGPT( - speaker + ": " + finalJAString, textHistory, True - ) + response = translateGPT(speaker + ": " + finalJAString, textHistory, True) tokens[0] += response[1][0] tokens[1] += response[1][1] translatedText = response[0] @@ -564,9 +552,7 @@ def translateGPT(t, history, fullPromptFlag): historyRaw = history inputTotalTokens = len(enc.encode(historyRaw)) + len(enc.encode(PROMPT)) - outputTotalTokens = ( - len(enc.encode(t)) * 2 - ) # Estimating 2x the size of the original text + outputTotalTokens = len(enc.encode(t)) * 2 # Estimating 2x the size of the original text totalTokens = [inputTotalTokens, outputTotalTokens] return (t, totalTokens) diff --git a/modules/text.py b/modules/text.py index cff1c25..3dce8f5 100644 --- a/modules/text.py +++ b/modules/text.py @@ -114,13 +114,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] == None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: @@ -224,9 +218,7 @@ def translateTxt(data, translatedList): stringList = None # Remove speaker - translatedText = re.sub( - r"^\[?(.+?)\]?\s?[|:]\s?", "", translatedText - ) + translatedText = re.sub(r"^\[?(.+?)\]?\s?[|:]\s?", "", translatedText) # # Textwrap # translatedText = textwrap.fill(translatedText, width=WIDTH) @@ -248,9 +240,7 @@ def translateTxt(data, translatedList): if stringList: PBAR.total = len(stringList) PBAR.refresh() - response = translateGPT( - stringList, "Reply with the English Translation", True - ) + response = translateGPT(stringList, "Reply with the English Translation", True) tokens[0] += response[1][0] tokens[1] += response[1][1] stringListTL = response[0] @@ -324,9 +314,7 @@ def batchList(input_list, batch_size): if not isinstance(batch_size, int) or batch_size <= 0: raise ValueError("batch_size must be a positive integer") - return [ - input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size) - ] + return [input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size)] def createContext(fullPromptFlag, subbedT, format): @@ -496,9 +484,7 @@ def translateGPT(text, history, fullPromptFlag): subbedT = varResponse[0] # Things to Check before starting translation - if not re.search( - r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", subbedT - ): + if not re.search(r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", subbedT): if PBAR is not None: PBAR.update(len(tItem)) history = tItem[-MAXHISTORY:] @@ -524,13 +510,9 @@ def translateGPT(text, history, fullPromptFlag): translatedText = cleanTranslatedText(translatedText, varResponse) if isinstance(tItem, list): extractedTranslations = extractTranslation(translatedText, True) - if extractedTranslations == None or len(tItem) != len( - extractedTranslations - ): + if extractedTranslations == None or len(tItem) != len(extractedTranslations): # Mismatch. Try Again - response = translateText( - system, user, history, 0.05, format, "gpt-4o" - ) + response = translateText(system, user, history, 0.05, format, "gpt-4o") translatedText = response.choices[0].message.content totalTokens[0] += response.usage.prompt_tokens totalTokens[1] += response.usage.completion_tokens diff --git a/modules/tyrano.py b/modules/tyrano.py index 3a21bee..15f63d9 100644 --- a/modules/tyrano.py +++ b/modules/tyrano.py @@ -114,13 +114,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] == None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: @@ -275,12 +269,8 @@ def translateTyrano(data, translatedList): # Remove speaker if speaker != "": - matchSpeakerList = re.findall( - r"^\[?(.+?)\]?\s?[|:]\s?", translatedText - ) - translatedText = re.sub( - r"^\[?(.+?)\]?\s?[|:]\s?", "", translatedText - ) + matchSpeakerList = re.findall(r"^\[?(.+?)\]?\s?[|:]\s?", translatedText) + translatedText = re.sub(r"^\[?(.+?)\]?\s?[|:]\s?", "", translatedText) # # Textwrap # translatedText = textwrap.fill(translatedText, width=WIDTH) @@ -326,9 +316,7 @@ def translateTyrano(data, translatedList): if stringList: PBAR.total = len(stringList) PBAR.refresh() - response = translateGPT( - stringList, "Reply with the English Translation", True - ) + response = translateGPT(stringList, "Reply with the English Translation", True) tokens[0] += response[1][0] tokens[1] += response[1][1] stringListTL = response[0] @@ -402,9 +390,7 @@ def batchList(input_list, batch_size): if not isinstance(batch_size, int) or batch_size <= 0: raise ValueError("batch_size must be a positive integer") - return [ - input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size) - ] + return [input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size)] def createContext(fullPromptFlag, subbedT, format): @@ -573,9 +559,7 @@ def translateGPT(text, history, fullPromptFlag): subbedT = varResponse[0] # Things to Check before starting translation - if not re.search( - r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", subbedT - ): + if not re.search(r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", subbedT): if PBAR is not None: PBAR.update(len(tItem)) history = tItem[-MAXHISTORY:] @@ -601,13 +585,9 @@ def translateGPT(text, history, fullPromptFlag): translatedText = cleanTranslatedText(translatedText, varResponse) if isinstance(tItem, list): extractedTranslations = extractTranslation(translatedText, True) - if extractedTranslations == None or len(tItem) != len( - extractedTranslations - ): + if extractedTranslations == None or len(tItem) != len(extractedTranslations): # Mismatch. Try Again - response = translateText( - system, user, history, 0.05, format, "gpt-4o" - ) + response = translateText(system, user, history, 0.05, format, "gpt-4o") translatedText = response.choices[0].message.content totalTokens[0] += response.usage.prompt_tokens totalTokens[1] += response.usage.completion_tokens diff --git a/modules/unity.py b/modules/unity.py index 780ac3f..78790d5 100644 --- a/modules/unity.py +++ b/modules/unity.py @@ -89,17 +89,13 @@ def handleUnity(filename, estimate): # Print any errors on maps if len(MISMATCH) > 0: - return ( - totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET - ) + return totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET else: return totalString else: try: - with open( - "translated/" + filename, "w", encoding="utf8", errors="ignore" - ) as outFile: + with open("translated/" + filename, "w", encoding="utf8", errors="ignore") as outFile: start = time.time() translatedData = openFiles(filename) @@ -134,13 +130,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] == None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: @@ -348,9 +338,7 @@ def batchList(input_list, batch_size): if not isinstance(batch_size, int) or batch_size <= 0: raise ValueError("batch_size must be a positive integer") - return [ - input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size) - ] + return [input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size)] def createContext(fullPromptFlag, subbedT, format): @@ -534,9 +522,7 @@ def translateGPT(text, history, fullPromptFlag): translatedText = cleanTranslatedText(translatedText, varResponse) if isinstance(tItem, list): extractedTranslations = extractTranslation(translatedText, True) - if extractedTranslations == None or len(tItem) != len( - extractedTranslations - ): + if extractedTranslations == None or len(tItem) != len(extractedTranslations): # Mismatch. Try Again response = translateText(system, user, history, 0.05, format, "gpt-4o") translatedText = response.choices[0].message.content @@ -547,17 +533,13 @@ def translateGPT(text, history, fullPromptFlag): translatedText = cleanTranslatedText(translatedText, varResponse) if isinstance(tItem, list): extractedTranslations = extractTranslation(translatedText, True) - if extractedTranslations == None or len(tItem) != len( - extractedTranslations - ): + if extractedTranslations == None or len(tItem) != len(extractedTranslations): mismatch = True # Just here for breakpoint # Set if no mismatch if mismatch == False: tList[index] = extractedTranslations - history = extractedTranslations[ - -10: - ] # Update history if we have a list + history = extractedTranslations[-10:] # Update history if we have a list else: history = text[-10:] mismatch = False diff --git a/modules/wolf.py b/modules/wolf.py index 62b0d90..f3b401c 100644 --- a/modules/wolf.py +++ b/modules/wolf.py @@ -168,13 +168,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] is None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: # Fail @@ -246,9 +240,7 @@ def parseMap(data, filename): totalLines += len(page["list"]) # Thread for each page in file - with tqdm( - bar_format=BAR_FORMAT, position=POSITION, total=totalLines, leave=LEAVE - ) as pbar: + with tqdm(bar_format=BAR_FORMAT, position=POSITION, total=totalLines, leave=LEAVE) as pbar: pbar.desc = filename pbar.total = totalLines with ThreadPoolExecutor(max_workers=THREADS) as executor: @@ -342,9 +334,7 @@ def searchCodes(events, pbar, jobList, filename): translatedText = stringList[0] # Remove speaker - matchSpeakerList = re.findall( - r"^(\[.+?\]\s?[|:]\s?)\s?", translatedText - ) + matchSpeakerList = re.findall(r"^(\[.+?\]\s?[|:]\s?)\s?", translatedText) if len(matchSpeakerList) > 0: translatedText = translatedText.replace(matchSpeakerList[0], "") @@ -440,9 +430,7 @@ def searchCodes(events, pbar, jobList, filename): # Adjust Speaker and Add Textwrap for j in range(len(list122TL)): list122TL[j] = textwrap.fill(list122TL[j], WIDTH) - list122TL[j] = re.sub( - r"^\[?(.+?)\]?:", r"\1:", list122TL[j] - ) + list122TL[j] = re.sub(r"^\[?(.+?)\]?:", r"\1:", list122TL[j]) list122TL[j] = list122TL[j].replace(":", ":\n") list122TL[j] = list122TL[j].replace(":\n ", ":\n") @@ -482,9 +470,9 @@ def searchCodes(events, pbar, jobList, filename): translatedText = textwrap.fill(translatedText, LISTWIDTH) # Set String - codeList[i]["stringArgs"][0] = codeList[i]["stringArgs"][ - 0 - ].replace(jaString, translatedText) + codeList[i]["stringArgs"][0] = codeList[i]["stringArgs"][0].replace( + jaString, translatedText + ) ### Event Code: 300 Common Events if ( @@ -579,19 +567,14 @@ def searchCodes(events, pbar, jobList, filename): and str != "\r\n" ): # Decide Wrap - if ( - codeList[i]["stringArgs"][0] - == "[移]サウンドノベル" - ): + if codeList[i]["stringArgs"][0] == "[移]サウンドノベル": width = 40 else: width = WIDTH # Add Textwrap and Font list300[0] = textwrap.fill(list300[0], width) - list300[0] = list300[0].replace( - "\n", f"\r\n\\f[{fontSize}]" - ) + list300[0] = list300[0].replace("\n", f"\r\n\\f[{fontSize}]") list300[0] = f"\\f[{fontSize}]{list300[0]}\r\n" translatedText += list300[0] list300.pop(0) @@ -720,9 +703,7 @@ def formatDramon(jaString): # Clean List cleanedList = [ - x - for x in jaStringList - if x is not None and x != "" and x != "\r\n" and x != "_SS_" + x for x in jaStringList if x is not None and x != "" and x != "\r\n" and x != "_SS_" ] # Iterate Through List @@ -868,9 +849,7 @@ def searchDB(events, pbar, jobList, filename): if dataList[j].get("value") != "": # Textwrap translatedText = NPCList[2][0] - translatedText = textwrap.fill( - translatedText, LISTWIDTH - ) + translatedText = textwrap.fill(translatedText, LISTWIDTH) translatedText = font + translatedText # Set Data @@ -929,9 +908,7 @@ def searchDB(events, pbar, jobList, filename): if setData == False: if dataList[j].get("value") != "": # Grab Choices - optionsList[1] = ( - dataList[j].get("value").split("\r\n") - ) + optionsList[1] = dataList[j].get("value").split("\r\n") # Translate response = translateGPT( @@ -950,9 +927,7 @@ def searchDB(events, pbar, jobList, filename): if setData == False: if dataList[j].get("value") != "": # Grab Choices - optionsList[1] = ( - dataList[j].get("value").split("\r\n") - ) + optionsList[1] = dataList[j].get("value").split("\r\n") # Translate response = translateGPT( @@ -971,9 +946,7 @@ def searchDB(events, pbar, jobList, filename): if setData == False: if dataList[j].get("value") != "": # Grab Choices - optionsList[1] = ( - dataList[j].get("value").split("\r\n") - ) + optionsList[1] = dataList[j].get("value").split("\r\n") # Translate response = translateGPT( @@ -1026,9 +999,7 @@ def searchDB(events, pbar, jobList, filename): if dataList[j].get("value") != "": # Textwrap translatedText = itemList[1][0] - translatedText = textwrap.fill( - translatedText, LISTWIDTH - ) + translatedText = textwrap.fill(translatedText, LISTWIDTH) translatedText = font + translatedText # Set Data @@ -1052,9 +1023,7 @@ def searchDB(events, pbar, jobList, filename): if dataList[j].get("value") != "": # Textwrap translatedText = itemList[2][0] - translatedText = textwrap.fill( - translatedText, LISTWIDTH - ) + translatedText = textwrap.fill(translatedText, LISTWIDTH) translatedText = font + translatedText # Set Data @@ -1078,9 +1047,7 @@ def searchDB(events, pbar, jobList, filename): if dataList[j].get("value") != "": # Textwrap translatedText = itemList[3][0] - translatedText = textwrap.fill( - translatedText, LISTWIDTH - ) + translatedText = textwrap.fill(translatedText, LISTWIDTH) translatedText = font + translatedText # Set Data @@ -1125,9 +1092,7 @@ def searchDB(events, pbar, jobList, filename): if dataList[j].get("value") != "": # Textwrap translatedText = armorList[1][0] - translatedText = textwrap.fill( - translatedText, LISTWIDTH - ) + translatedText = textwrap.fill(translatedText, LISTWIDTH) translatedText = font + translatedText # Set Data @@ -1172,9 +1137,7 @@ def searchDB(events, pbar, jobList, filename): if dataList[j].get("value") != "": # Textwrap translatedText = enemyList[1][0] - translatedText = textwrap.fill( - translatedText, LISTWIDTH - ) + translatedText = textwrap.fill(translatedText, LISTWIDTH) translatedText = font + translatedText # Set Data @@ -1219,9 +1182,7 @@ def searchDB(events, pbar, jobList, filename): if dataList[j].get("value") != "": # Textwrap translatedText = weaponsList[1][0] - translatedText = textwrap.fill( - translatedText, LISTWIDTH - ) + translatedText = textwrap.fill(translatedText, LISTWIDTH) translatedText = font + translatedText # Set Data @@ -1266,9 +1227,7 @@ def searchDB(events, pbar, jobList, filename): if dataList[j].get("value") != "": # Textwrap translatedText = skillList[1][0] - translatedText = textwrap.fill( - translatedText, LISTWIDTH - ) + translatedText = textwrap.fill(translatedText, LISTWIDTH) translatedText = font + translatedText # Set Data @@ -1325,9 +1284,7 @@ def searchDB(events, pbar, jobList, filename): # translatedText = translatedText.replace('Taro', '') # Textwrap - translatedText = textwrap.fill( - translatedText, LISTWIDTH - ) + translatedText = textwrap.fill(translatedText, LISTWIDTH) translatedText = font + translatedText # Set Data @@ -1359,9 +1316,7 @@ def searchDB(events, pbar, jobList, filename): # translatedText = translatedText.replace('Taro', '') # Textwrap - translatedText = textwrap.fill( - translatedText, LISTWIDTH - ) + translatedText = textwrap.fill(translatedText, LISTWIDTH) translatedText = font + translatedText # Set Data @@ -1393,9 +1348,7 @@ def searchDB(events, pbar, jobList, filename): # Name response = translateGPT( NPCList[0], - "Reply with only the " - + LANGUAGE - + " translation of the RPG enemy name", + "Reply with only the " + LANGUAGE + " translation of the RPG enemy name", True, ) nameListTL = response[0] @@ -1458,9 +1411,7 @@ def searchDB(events, pbar, jobList, filename): # Desc 1 response = translateGPT( scenarioList[1], - "reply with only the gender neutral " - + LANGUAGE - + " translation of the NPC name", + "reply with only the gender neutral " + LANGUAGE + " translation of the NPC name", True, ) descListTL1 = response[0] @@ -1469,9 +1420,7 @@ def searchDB(events, pbar, jobList, filename): # Desc 2 response = translateGPT( scenarioList[2], - "reply with only the gender neutral " - + LANGUAGE - + " translation of the NPC name", + "reply with only the gender neutral " + LANGUAGE + " translation of the NPC name", True, ) descListTL2 = response[0] @@ -1570,9 +1519,7 @@ def searchDB(events, pbar, jobList, filename): totalTokens[1] += response[1][1] # Check Mismatch - if len(nameListTL) != len(armorList[0]) or len(descListTL1) != len( - armorList[1] - ): + if len(nameListTL) != len(armorList[0]) or len(descListTL1) != len(armorList[1]): with LOCK: if filename not in MISMATCH: MISMATCH.append(filename) @@ -1592,9 +1539,7 @@ def searchDB(events, pbar, jobList, filename): # Name response = translateGPT( enemyList[0], - "Reply with only the " - + LANGUAGE - + " translation of the enemy NPC name", + "Reply with only the " + LANGUAGE + " translation of the enemy NPC name", True, ) nameListTL = response[0] @@ -1609,9 +1554,7 @@ def searchDB(events, pbar, jobList, filename): totalTokens[1] += response[1][1] # Check Mismatch - if len(nameListTL) != len(enemyList[0]) or len(descListTL1) != len( - enemyList[1] - ): + if len(nameListTL) != len(enemyList[0]) or len(descListTL1) != len(enemyList[1]): with LOCK: if filename not in MISMATCH: MISMATCH.append(filename) @@ -1631,9 +1574,7 @@ def searchDB(events, pbar, jobList, filename): # Name response = translateGPT( weaponsList[0], - "Reply with only the " - + LANGUAGE - + " translation of the RPG weapon name", + "Reply with only the " + LANGUAGE + " translation of the RPG weapon name", True, ) nameListTL = response[0] @@ -1675,9 +1616,7 @@ def searchDB(events, pbar, jobList, filename): # Name response = translateGPT( skillList[0], - "Reply with only the " - + LANGUAGE - + " translation of the RPG skill name", + "Reply with only the " + LANGUAGE + " translation of the RPG skill name", True, ) nameListTL = response[0] @@ -1846,9 +1785,7 @@ def batchList(input_list, batch_size): if not isinstance(batch_size, int) or batch_size <= 0: raise ValueError("batch_size must be a positive integer") - return [ - input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size) - ] + return [input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size)] def createContext(fullPromptFlag, subbedT, format): @@ -2013,9 +1950,7 @@ def translateGPT(text, history, fullPromptFlag): subbedT = varResponse[0] # Things to Check before starting translation - if not re.search( - r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", subbedT - ): + if not re.search(r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+", subbedT): if PBAR is not None: PBAR.update(len(tItem)) history = tItem[-MAXHISTORY:] @@ -2041,13 +1976,9 @@ def translateGPT(text, history, fullPromptFlag): translatedText = cleanTranslatedText(translatedText, varResponse) if isinstance(tItem, list): extractedTranslations = extractTranslation(translatedText, True) - if extractedTranslations == None or len(tItem) != len( - extractedTranslations - ): + if extractedTranslations == None or len(tItem) != len(extractedTranslations): # Mismatch. Try Again - response = translateText( - system, user, history, 0.05, format, "gpt-4o" - ) + response = translateText(system, user, history, 0.05, format, "gpt-4o") translatedText = response.choices[0].message.content totalTokens[0] += response.usage.prompt_tokens totalTokens[1] += response.usage.completion_tokens diff --git a/modules/wolf2.py b/modules/wolf2.py index 915c4ea..cee80fc 100644 --- a/modules/wolf2.py +++ b/modules/wolf2.py @@ -80,9 +80,7 @@ def handleWOLF2(filename, estimate): # Print any errors on maps if len(MISMATCH) > 0: - return ( - totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET - ) + return totalString + Fore.RED + f"\nMismatch Errors: {MISMATCH}" + Fore.RESET else: return totalString @@ -125,13 +123,7 @@ def getResultString(translatedData, translationTime, filename): if translatedData[2] == None: # Success return ( - filename - + ": " - + totalTokenstring - + timeString - + Fore.GREEN - + " \u2713 " - + Fore.RESET + filename + ": " + totalTokenstring + timeString + Fore.GREEN + " \u2713 " + Fore.RESET ) else: @@ -248,10 +240,7 @@ def translateWOLF(data, translatedList, pbar, filename): currentGroup.append(data[i]) i += 1 while ( - i < len(data) - and r"/" not in data[i] - and "@" not in data[i] - and data[i] != "\n" + i < len(data) and r"/" not in data[i] and "@" not in data[i] and data[i] != "\n" ): currentGroup.append(data[i]) i += 1 @@ -276,10 +265,7 @@ def translateWOLF(data, translatedList, pbar, filename): else: # Insert Strings while ( - i < len(data) - and r"/" not in data[i] - and "@" not in data[i] - and data[i] != "\n" + i < len(data) and r"/" not in data[i] and "@" not in data[i] and data[i] != "\n" ): data.pop(i) @@ -405,9 +391,7 @@ def batchList(input_list, batch_size): if not isinstance(batch_size, int) or batch_size <= 0: raise ValueError("batch_size must be a positive integer") - return [ - input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size) - ] + return [input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size)] def createContext(fullPromptFlag, subbedT): @@ -643,13 +627,9 @@ def translateGPT(text, history, fullPromptFlag): translatedText = cleanTranslatedText(translatedText, varResponse) if isinstance(tItem, list): extractedTranslations = extractTranslation(translatedText, True) - if extractedTranslations == None or len(tItem) != len( - extractedTranslations - ): + if extractedTranslations == None or len(tItem) != len(extractedTranslations): # Mismatch. Try Again - response = translateText( - characters, system, user, history, 0.05, format - ) + response = translateText(characters, system, user, history, 0.05, format) translatedText = response.choices[0].message.content totalTokens[0] += response.usage.prompt_tokens totalTokens[1] += response.usage.completion_tokens @@ -658,17 +638,13 @@ def translateGPT(text, history, fullPromptFlag): translatedText = cleanTranslatedText(translatedText, varResponse) if isinstance(tItem, list): extractedTranslations = extractTranslation(translatedText, True) - if extractedTranslations == None or len(tItem) != len( - extractedTranslations - ): + if extractedTranslations == None or len(tItem) != len(extractedTranslations): mismatch = True # Just here for breakpoint # Set if no mismatch if mismatch == False: tList[index] = extractedTranslations - history = extractedTranslations[ - -10: - ] # Update history if we have a list + history = extractedTranslations[-10:] # Update history if we have a list else: history = text[-10:] mismatch = False