From 752249e1bdb30ef811731a9bb028eff40d5c4a39 Mon Sep 17 00:00:00 2001 From: Dazed Date: Mon, 27 Nov 2023 06:22:54 -0600 Subject: [PATCH] Couple of updates to speakers --- modules/json.py | 2 +- modules/lune.py | 2 +- modules/rpgmakerace.py | 4 +-- modules/rpgmakermvmz.py | 59 +++++++++++++++++++++++++++-------------- prompt.example | 25 +++++++---------- 5 files changed, 53 insertions(+), 39 deletions(-) diff --git a/modules/json.py b/modules/json.py index 3c6002a..ed5640b 100644 --- a/modules/json.py +++ b/modules/json.py @@ -166,7 +166,7 @@ def translateJSON(data, pbar): # Translate if jaString != '': - response = translateGPT(f'{speaker} | {jaString}', textHistory, True) + response = translateGPT(f'{speaker}: {jaString}', textHistory, True) tokens[0] += response[1][0] tokens[1] += response[1][1] translatedText = response[0] diff --git a/modules/lune.py b/modules/lune.py index 9d2a034..6c684e6 100644 --- a/modules/lune.py +++ b/modules/lune.py @@ -166,7 +166,7 @@ def translateJSON(data, pbar): # Translate if jaString != '': - response = translateGPT(f'{speaker} | {jaString}', textHistory, True) + response = translateGPT(f'{speaker}: {jaString}', textHistory, True) tokens[0] += response[1][0] tokens[1] += response[1][1] translatedText = response[0] diff --git a/modules/rpgmakerace.py b/modules/rpgmakerace.py index 5b7de11..d5337a2 100644 --- a/modules/rpgmakerace.py +++ b/modules/rpgmakerace.py @@ -793,7 +793,7 @@ def searchCodes(page, pbar): subbedT = varResponse[0] textHistory.append('\"' + varResponse[0] + '\"') elif finalJAString != '': - response = translateGPT(speaker + ' | ' + finalJAString, textHistory, True) + response = translateGPT(speaker + ': ' + finalJAString, textHistory, True) totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] translatedText = response[0] @@ -804,7 +804,7 @@ def searchCodes(page, pbar): # Sub Vars varResponse = subVars(translatedText) subbedT = varResponse[0] - textHistory.append('\"' + speaker + ' | ' + varResponse[0] + '\"') + textHistory.append('\"' + speaker + ': ' + varResponse[0] + '\"') speaker = '' else: translatedText = finalJAString diff --git a/modules/rpgmakermvmz.py b/modules/rpgmakermvmz.py index e897e9c..53ad8da 100644 --- a/modules/rpgmakermvmz.py +++ b/modules/rpgmakermvmz.py @@ -61,7 +61,7 @@ CODE108 = False NAMES = False # Output a list of all the character names found BRFLAG = False # If the game uses
instead FIXTEXTWRAP = True -IGNORETLTEXT = True +IGNORETLTEXT = False def handleMVMZ(filename, estimate): global ESTIMATE, totalTokens @@ -616,6 +616,7 @@ def searchCodes(page, pbar): # Join up 401 groups for better translation. if len(currentGroup) > 0: finalJAString = ''.join(currentGroup) + finalJAString = finalJAString.replace('?', '?') oldjaString = finalJAString # Color Regex: ^([\\]+[cC]\[[0-9]\]+(.+?)[\\]+[cC]\[[0]\]) @@ -653,10 +654,9 @@ def searchCodes(page, pbar): matchList = re.findall(r'(\\+nc<(.*?)>)(.+)?', finalJAString) if len(matchList) != 0: # Translate Speaker - response = translateGPT(matchList[0][1], 'Reply with only the '+ LANGUAGE +' translation of the NPC name', False) - totalTokens[0] += response[1][0] - totalTokens[1] += response[1][1] - speaker = response[0].strip('.') + speaker = getSpeaker(matchList[0][1]) + + # Set Nametag and Remove from Final String nametag = matchList[0][0].replace(matchList[0][1], speaker) finalJAString = finalJAString.replace(matchList[0][0], '') @@ -671,10 +671,8 @@ def searchCodes(page, pbar): elif '\\nw' in finalJAString or '\\NW' in finalJAString: matchList = re.findall(r'([\\]+[nN][wW]\[(.+?)\]+)(.+)', finalJAString) if len(matchList) != 0: - response = translateGPT(matchList[0][1], 'Reply with only the '+ LANGUAGE +' translation of the NPC name', False) - totalTokens[0] += response[1][0] - totalTokens[1] += response[1][1] - speaker = response[0].strip('.') + # Translate Speaker + speaker = getSpeaker(matchList[0][1]) # Set Nametag and Remove from Final String nametag = matchList[0][0].replace(matchList[0][1], speaker) @@ -696,17 +694,14 @@ def searchCodes(page, pbar): match1 = matchList[0][3] # Translate Speaker - response = translateGPT(match1, 'Reply with only the '+ LANGUAGE +' translation of the NPC name', True) - totalTokens[0] += response[1][0] - totalTokens[1] += response[1][1] - speaker = response[0].strip('.') + speaker = getSpeaker(match1) # Set Nametag and Remove from Final String nametag = match0.replace(match1, speaker) finalJAString = finalJAString.replace(match0, '') # Set next item as dialogue - if (codeList[j + 1]['code'] == 401 and len(codeList[j + 1]['parameters']) > 0): + if codeList[j + 1]['code'] == 401 or codeList[j + 1]['code'] == -1: # Set name var to top of list codeList[j]['parameters'] = [nametag] codeList[j]['code'] = code @@ -740,6 +735,7 @@ def searchCodes(page, pbar): finalJAString = finalJAString.replace('―', '-') finalJAString = finalJAString.replace('ー', '-') finalJAString = finalJAString.replace('…', '...') + finalJAString = re.sub(r'(\.{3}\.+)', '...', finalJAString) finalJAString = finalJAString.replace(' ', '') # finalJAString = finalJAString.replace('〇', '*') @@ -781,7 +777,7 @@ def searchCodes(page, pbar): varResponse = subVars(translatedText) textHistory.append('\"' + varResponse[0] + '\"') elif finalJAString != '': - response = translateGPT(speaker + ' | ' + finalJAString, textHistory, True) + response = translateGPT(speaker + ': ' + finalJAString, textHistory, True) totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] translatedText = response[0] @@ -791,7 +787,7 @@ def searchCodes(page, pbar): # Sub Vars varResponse = subVars(translatedText) - textHistory.append('\"' + speaker + ' | ' + varResponse[0] + '\"') + textHistory.append('\"' + speaker + ': ' + varResponse[0] + '\"') speaker = '' else: translatedText = finalJAString @@ -1735,6 +1731,27 @@ def searchSystem(data, pbar): return totalTokens +# Save some money and enter the character before translation +def getSpeaker(speaker): + match speaker: + case 'アイル': + return 'Aeru' + case 'リラ': + return 'Lira' + case 'アザミ': + return 'Azami' + case 'マーガレット': + return 'Margaret' + case 'ミール': + return 'Miiru' + case 'ライト': + return 'Light' + case _: + response = translateGPT(speaker, 'Reply with only the '+ LANGUAGE +' translation of the NPC name', False) + totalTokens[0] += response[1][0] + totalTokens[1] += response[1][1] + return response[0].strip('.') + def subVars(jaString): jaString = jaString.replace('\u3000', ' ') @@ -1881,10 +1898,12 @@ def translateGPT(t, history, fullPromptFlag): # Characters context = 'Game Characters:\ - Character: リッカ == Ricca - Gender: Female\ - Character: シーナ == Sina - Gender: Female\ - Character: ヘレナ == Helena - Gender: Female\ - Character: Miko == Miko - Gender: Female' + Character: アイル == Aeru - Gender: Male\ + Character: リラ == Lira - Gender: Female\ + Character: アザミ == Azami - Gender: Female\ + Character: マーガレット == Margaret - Gender: Female\ + Character: ミール == Miiru - Gender: Female\ + Character: ライト == Light - Gender: Male' # Prompt if fullPromptFlag: diff --git a/prompt.example b/prompt.example index 7874f6d..408db37 100644 --- a/prompt.example +++ b/prompt.example @@ -8,23 +8,21 @@ There are 2 pieces of information the user will give you to help with translatio Use the following step-by-step instructions to respond to user inputs. Step 1 - Receive Text -You receive a line of text to translate everything in the following format: - -`Line to Translate = ` or `Line to Translate = | ` +You receive a line of text to translate everything in the following format: Line to Translate = Step 2 - Output Text -You output in English the translation in the following format: - -`Translation: ` or `Translation: | ` +You output in English the translation in the following format: Translation = Other Notes: +- Only reply in English, even if it may be hard to translate. - If the speaker is '???' then they are unknown so leave it as is. - Pay attention to the gender of the subjects and characters. Avoid misgendering characters. -- Maintain any spacing in the translation +- Maintain any spacing in the translation. +- Maintain any code in brackets if given. +- Maintain the speaker if given. - Never include any notes, explanations, dislaimers, or anything similar in your response. - Maintain Japanese Honorifics. For example: 'サクラねえちゃん' == 'Sakura Onee-san' - "--" is intentional and indicates a blank in the text. Leave it as is. -- If there is no speaker, do not add one. - Translate 'おまんこ' as 'pussy'. - Translate 'お尻' as 'butt' - Translate '尻' as 'ass' @@ -37,10 +35,7 @@ Other Notes: - Translate 'ヒク' as 'biku' - Translate 'ムク' as 'muku' -Maintain the following codes in your translation if they exist: -- {Nested_} - Nested -- {Ascii_} - Ascii -- {Color_} - Color -- {N_} - Noun -- {Vars_} - Var -- {FCode_} - Format \ No newline at end of file +Sometimes, the text may contain 'tags' in the format of {_}. +Maintain these tags only if they exist in the untranslated text. + +Color - A tag that colors the wrapped text. \ No newline at end of file