From 722aa25077f8984d05de1aabb3aed20808050d15 Mon Sep 17 00:00:00 2001 From: m5kro Date: Fri, 17 Nov 2023 13:04:46 -0800 Subject: [PATCH] Translate to Different Languages --- .env.example | 2 + modules/alltext.py | 54 +++++++++++------------- modules/csv.py | 9 ++-- modules/json.py | 9 ++-- modules/kansen.py | 9 ++-- modules/lune.py | 9 ++-- modules/lune2.py | 9 ++-- modules/rpgmakerace.py | 89 ++++++++++++++++++++-------------------- modules/rpgmakermvmz.py | 91 +++++++++++++++++++++-------------------- modules/txt.py | 7 ++-- modules/tyrano.py | 9 ++-- 11 files changed, 152 insertions(+), 145 deletions(-) diff --git a/.env.example b/.env.example index 3025c8a..440756d 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,4 @@ key="" organization="" +#The language to translate TO, Don't forget to change the prompt +language="" diff --git a/modules/alltext.py b/modules/alltext.py index f59aa2e..150f79b 100644 --- a/modules/alltext.py +++ b/modules/alltext.py @@ -16,14 +16,15 @@ import openai from retry import retry from tqdm import tqdm -#Globals +# Globals load_dotenv() openai.organization = os.getenv('org') openai.api_key = os.getenv('key') +LANGUAGE = os.getenv('language').capitalize() -APICOST = .002 # Depends on the model https://openai.com/pricing +APICOST = .002 # Depends on the model https://openai.com/pricing PROMPT = Path('prompt.txt').read_text(encoding='utf-8') -THREADS = 10 # For GPT4 rate limit will be hit if you have more than 1 thread. +THREADS = 10 # For GPT4 rate limit will be hit if you have more than 1 thread. LOCK = threading.Lock() WIDTH = 60 LISTWIDTH = 60 @@ -34,10 +35,10 @@ TOKENS = 0 TOTALTOKENS = 0 NAMESLIST = [] -#tqdm Globals -BAR_FORMAT='{l_bar}{bar:10}{r_bar}{bar:-10b}' -POSITION=0 -LEAVE=False +# tqdm Globals +BAR_FORMAT = '{l_bar}{bar:10}{r_bar}{bar:-10b}' +POSITION = 0 +LEAVE = False def handleAllText(filename, estimate): global ESTIMATE, TOKENS, TOTALTOKENS, TOTALCOST @@ -55,7 +56,7 @@ def handleAllText(filename, estimate): TOTALTOKENS += TOKENS TOKENS = 0 os.remove('translated/' + filename) - + else: # Print Result end = time.time() @@ -74,7 +75,7 @@ def openFiles(filename, writeFile): def getResultString(translatedData, translationTime, filename): # File Print String tokenString = Fore.YELLOW + '[' + str(translatedData[1]) + \ - ' Tokens/${:,.4f}'.format(translatedData[1] * .001 * APICOST) + ']' + ' Tokens/${:,.4f}'.format(translatedData[1] * .001 * APICOST) + ']' timeString = Fore.BLUE + '[' + str(round(translationTime, 1)) + 's]' if translatedData[2] == None: @@ -87,9 +88,9 @@ def getResultString(translatedData, translationTime, filename): raise translatedData[2] except Exception as e: errorString = str(e) + '|' + translatedData[3] + Fore.RED - return filename + ': ' + tokenString + timeString + Fore.RED + u' \u2717 ' +\ - errorString + Fore.RESET - + return filename + ': ' + tokenString + timeString + Fore.RED + u' \u2717 ' + \ + errorString + Fore.RESET + @retry(exceptions=Exception, tries=5, delay=5) def translateGPT(t, history, fullPromptFlag): # If ESTIMATE is True just count this as an execution and return. @@ -97,23 +98,23 @@ def translateGPT(t, history, fullPromptFlag): enc = tiktoken.encoding_for_model("gpt-4") tokens = len(enc.encode(t)) * 2 + len(enc.encode(str(history))) + len(enc.encode(PROMPT)) return (t, tokens) - + # Sub Vars varResponse = subVars(t) subbedT = varResponse[0] # If there isn't any Japanese in the text just skip - if not re.search(r'[ˆê-êž]+|[‚Ÿ-?]+|[ƒ@-ƒ”]+|[\uFF00-\uFFEF]', subbedT): - return(t, 0) + if not re.search(r'[��-�]+|[��-?]+|[�@-��]+|[\uFF00-\uFFEF]', subbedT): + return (t, 0) # Characters context = '```\ Game Characters:\ - Character: ’rƒmã ‘ñŠC == Ikenoue Takumi - Gender: Male\ - Character: •Ÿ‰i ‚±‚Í‚é == Fukunaga Koharu - Gender: Female\ - Character: _ò —‰› == Kamiizumi Rio - Gender: Female\ - Character: ‹gËŽ› ƒAƒŠƒT == Kisshouji Arisa - Gender: Female\ - Character: ‹v‰ä —F—¢Žq == Kuga Yuriko - Gender: Female\ + Character: �r�m�� ��C == Ikenoue Takumi - Gender: Male\ + Character: ���i ���͂� == Fukunaga Koharu - Gender: Female\ + Character: �_�� ���� == Kamiizumi Rio - Gender: Female\ + Character: �g�ˎ� �A���T == Kisshouji Arisa - Gender: Female\ + Character: �v�� �F���q == Kuga Yuriko - Gender: Female\ ```' # Prompt @@ -121,7 +122,7 @@ def translateGPT(t, history, fullPromptFlag): system = PROMPT user = 'Line to Translate = ' + subbedT else: - system = 'Output ONLY the english translation in the following format: `Translation: `' + system = 'Output ONLY the ' + LANGUAGE + ' translation in the following format: `Translation: <' + LANGUAGE.upper() + '_TRANSLATION>`' user = 'Line to Translate = ' + subbedT # Create Message List @@ -152,18 +153,13 @@ def translateGPT(t, history, fullPromptFlag): translatedText = resubVars(translatedText, varResponse[1]) # Remove Placeholder Text - translatedText = translatedText.replace('English Translation: ', '') + translatedText = translatedText.replace(LANGUAGE + ' Translation: ', '') translatedText = translatedText.replace('Translation: ', '') translatedText = translatedText.replace('Line to Translate = ', '') - translatedText = translatedText.replace('Translation = ', '') + translatedText = translatedText.replace(LANGUAGE + ' Translation = ', '') translatedText = translatedText.replace('Translate = ', '') - translatedText = translatedText.replace('English Translation:', '') - translatedText = translatedText.replace('Translation:', '') - translatedText = translatedText.replace('Line to Translate =', '') - translatedText = translatedText.replace('Translation =', '') - translatedText = translatedText.replace('Translate =', '') translatedText = re.sub(r'Note:.*', '', translatedText) - translatedText = translatedText.replace('‚Á', '') + translatedText = translatedText.replace('��', '') # Return Translation if len(translatedText) > 15 * len(t) or "I'm sorry, but I'm unable to assist with that translation" in translatedText: diff --git a/modules/csv.py b/modules/csv.py index 7112ef2..f546db2 100644 --- a/modules/csv.py +++ b/modules/csv.py @@ -20,6 +20,7 @@ from tqdm import tqdm load_dotenv() openai.organization = os.getenv('org') openai.api_key = os.getenv('key') +LANGUAGE=os.getenv('language').capitalize() APICOST = .002 # Depends on the model https://openai.com/pricing PROMPT = Path('prompt.txt').read_text(encoding='utf-8') @@ -171,7 +172,7 @@ def translateCSV(row, pbar, writer, textHistory, format): text = match[1] # Translate Speaker - response = translateGPT (speaker, 'Reply with the English translation of the NPC name.', True) + response = translateGPT (speaker, 'Reply with the '+ LANGUAGE +' translation of the NPC name.', True) translatedSpeaker = response[0] tokens += response[1] @@ -347,7 +348,7 @@ def translateGPT(t, history, fullPromptFlag): system = PROMPT user = 'Line to Translate = ' + subbedT else: - system = 'Output ONLY the english translation in the following format: `Translation: `' + system = 'Output ONLY the '+ LANGUAGE +' translation in the following format: `Translation: <'+ LANGUAGE.upper() +'_TRANSLATION>`' user = 'Line to Translate = ' + subbedT # Create Message List @@ -378,12 +379,12 @@ def translateGPT(t, history, fullPromptFlag): translatedText = resubVars(translatedText, varResponse[1]) # Remove Placeholder Text - translatedText = translatedText.replace('English Translation: ', '') + translatedText = translatedText.replace(LANGUAGE +' Translation: ', '') translatedText = translatedText.replace('Translation: ', '') translatedText = translatedText.replace('Line to Translate = ', '') translatedText = translatedText.replace('Translation = ', '') translatedText = translatedText.replace('Translate = ', '') - translatedText = translatedText.replace('English Translation:', '') + translatedText = translatedText.replace(LANGUAGE +' Translation:', '') translatedText = translatedText.replace('Translation:', '') translatedText = translatedText.replace('Line to Translate =', '') translatedText = translatedText.replace('Translation =', '') diff --git a/modules/json.py b/modules/json.py index 402c8aa..01a4b25 100644 --- a/modules/json.py +++ b/modules/json.py @@ -19,6 +19,7 @@ from tqdm import tqdm load_dotenv() openai.organization = os.getenv('org') openai.api_key = os.getenv('key') +LANGUAGE=os.getenv('language').capitalize() INPUTAPICOST = .002 # Depends on the model https://openai.com/pricing OUTPUTAPICOST = .002 @@ -140,7 +141,7 @@ def translateJSON(data, pbar): # Speaker if 'name' in item[1]: if item[1]['name'] not in [None, '-']: - response = translateGPT(item[1]['name'], 'Reply with only the english translation of the NPC name', False) + response = translateGPT(item[1]['name'], 'Reply with only the '+ LANGUAGE +' translation of the NPC name', False) speaker = response[0] tokens[0] += response[1][0] tokens[1] += response[1][1] @@ -328,7 +329,7 @@ def translateGPT(t, history, fullPromptFlag): system = PROMPT user = 'Line to Translate = ' + subbedT else: - system = 'Output ONLY the english translation in the following format: `Translation: `' + system = 'Output ONLY the '+ LANGUAGE +' translation in the following format: `Translation: <'+ LANGUAGE.upper() +'_TRANSLATION>`' user = 'Line to Translate = ' + subbedT # Create Message List @@ -359,12 +360,12 @@ def translateGPT(t, history, fullPromptFlag): translatedText = resubVars(translatedText, varResponse[1]) # Remove Placeholder Text - translatedText = translatedText.replace('English Translation: ', '') + translatedText = translatedText.replace(LANGUAGE +' Translation: ', '') translatedText = translatedText.replace('Translation: ', '') translatedText = translatedText.replace('Line to Translate = ', '') translatedText = translatedText.replace('Translation = ', '') translatedText = translatedText.replace('Translate = ', '') - translatedText = translatedText.replace('English Translation:', '') + translatedText = translatedText.replace(LANGUAGE +' Translation:', '') translatedText = translatedText.replace('Translation:', '') translatedText = translatedText.replace('Line to Translate =', '') translatedText = translatedText.replace('Translation =', '') diff --git a/modules/kansen.py b/modules/kansen.py index 464599e..7a81b5e 100644 --- a/modules/kansen.py +++ b/modules/kansen.py @@ -18,6 +18,7 @@ from tqdm import tqdm load_dotenv() openai.organization = os.getenv('org') openai.api_key = os.getenv('key') +LANGUAGE=os.getenv('language').capitalize() APICOST = .002 # Depends on the model https://openai.com/pricing PROMPT = Path('prompt.txt').read_text(encoding='utf-8') @@ -127,7 +128,7 @@ def translateTyrano(data, pbar): if '[ns]' in data[i]: matchList = re.findall(r'\[ns\](.+?)\[', data[i]) if len(matchList) != 0: - response = translateGPT(matchList[0], 'Reply with only the english translation of the NPC name', True) + response = translateGPT(matchList[0], 'Reply with only the '+ LANGUAGE +' translation of the NPC name', True) speaker = response[0] tokens += response[1] data[i] = '[ns]' + speaker + '[nse]\n' @@ -488,7 +489,7 @@ def translateGPT(t, history, fullPromptFlag): system = PROMPT user = 'Line to Translate = ' + subbedT else: - system = 'Output ONLY the english translation in the following format: `Translation: `' + system = 'Output ONLY the '+ LANGUAGE +' translation in the following format: `Translation: <'+ LANGUAGE.upper() +'_TRANSLATION>`' user = 'Line to Translate = ' + subbedT # Create Message List @@ -519,12 +520,12 @@ def translateGPT(t, history, fullPromptFlag): translatedText = resubVars(translatedText, varResponse[1]) # Remove Placeholder Text - translatedText = translatedText.replace('English Translation: ', '') + translatedText = translatedText.replace(LANGUAGE +' Translation: ', '') translatedText = translatedText.replace('Translation: ', '') translatedText = translatedText.replace('Line to Translate = ', '') translatedText = translatedText.replace('Translation = ', '') translatedText = translatedText.replace('Translate = ', '') - translatedText = translatedText.replace('English Translation:', '') + translatedText = translatedText.replace(LANGUAGE +' Translation:', '') translatedText = translatedText.replace('Translation:', '') translatedText = translatedText.replace('Line to Translate =', '') translatedText = translatedText.replace('Translation =', '') diff --git a/modules/lune.py b/modules/lune.py index f3548c2..c0eb21a 100644 --- a/modules/lune.py +++ b/modules/lune.py @@ -19,6 +19,7 @@ from tqdm import tqdm load_dotenv() openai.organization = os.getenv('org') openai.api_key = os.getenv('key') +LANGUAGE=os.getenv('language').capitalize() INPUTAPICOST = .002 # Depends on the model https://openai.com/pricing OUTPUTAPICOST = .002 @@ -141,7 +142,7 @@ def translateJSON(data, pbar): # Speaker if 'name' in item: if item['name'] not in [None, '-']: - response = translateGPT(item['name'], 'Reply with only the english translation of the NPC name', False) + response = translateGPT(item['name'], 'Reply with only the '+ LANGUAGE +' translation of the NPC name', False) speaker = response[0] tokens[0] += response[1][0] tokens[1] += response[1][1] @@ -328,7 +329,7 @@ def translateGPT(t, history, fullPromptFlag): system = PROMPT user = 'Line to Translate = ' + subbedT else: - system = 'Output ONLY the english translation in the following format: `Translation: `' + system = 'Output ONLY the '+ LANGUAGE +' translation in the following format: `Translation: <'+ LANGUAGE.upper() +'_TRANSLATION>`' user = 'Line to Translate = ' + subbedT # Create Message List @@ -359,12 +360,12 @@ def translateGPT(t, history, fullPromptFlag): translatedText = resubVars(translatedText, varResponse[1]) # Remove Placeholder Text - translatedText = translatedText.replace('English Translation: ', '') + translatedText = translatedText.replace(LANGUAGE +' Translation: ', '') translatedText = translatedText.replace('Translation: ', '') translatedText = translatedText.replace('Line to Translate = ', '') translatedText = translatedText.replace('Translation = ', '') translatedText = translatedText.replace('Translate = ', '') - translatedText = translatedText.replace('English Translation:', '') + translatedText = translatedText.replace(LANGUAGE +' Translation:', '') translatedText = translatedText.replace('Translation:', '') translatedText = translatedText.replace('Line to Translate =', '') translatedText = translatedText.replace('Translation =', '') diff --git a/modules/lune2.py b/modules/lune2.py index 5ba9c9d..9081f27 100644 --- a/modules/lune2.py +++ b/modules/lune2.py @@ -20,6 +20,7 @@ from tqdm import tqdm load_dotenv() openai.organization = os.getenv('org') openai.api_key = os.getenv('key') +LANGUAGE=os.getenv('language').capitalize() APICOST = .002 # Depends on the model https://openai.com/pricing PROMPT = Path('prompt.txt').read_text(encoding='utf-8') @@ -185,7 +186,7 @@ def translateText(data, pbar): jaString = jaString.replace('å‹é‡Œå­', 'Yuriko') # Translate Speaker - response = translateGPT(jaString, 'Reply with only the english translation of the NPC name', True) + response = translateGPT(jaString, 'Reply with only the '+ LANGUAGE +' translation of the NPC name', True) tokens += response[1] speaker = response[0].strip('.') data[i] = speaker + '\n' @@ -374,7 +375,7 @@ def translateGPT(t, history, fullPromptFlag): system = PROMPT user = 'Line to Translate = ' + subbedT else: - system = 'Output ONLY the english translation in the following format: `Translation: `' + system = 'Output ONLY the '+ LANGUAGE +' translation in the following format: `Translation: <'+ LANGUAGE.upper() +'_TRANSLATION>`' user = 'Line to Translate = ' + subbedT # Create Message List @@ -405,12 +406,12 @@ def translateGPT(t, history, fullPromptFlag): translatedText = resubVars(translatedText, varResponse[1]) # Remove Placeholder Text - translatedText = translatedText.replace('English Translation: ', '') + translatedText = translatedText.replace(LANGUAGE +' Translation: ', '') translatedText = translatedText.replace('Translation: ', '') translatedText = translatedText.replace('Line to Translate = ', '') translatedText = translatedText.replace('Translation = ', '') translatedText = translatedText.replace('Translate = ', '') - translatedText = translatedText.replace('English Translation:', '') + translatedText = translatedText.replace(LANGUAGE +' Translation:', '') translatedText = translatedText.replace('Translation:', '') translatedText = translatedText.replace('Line to Translate =', '') translatedText = translatedText.replace('Translation =', '') diff --git a/modules/rpgmakerace.py b/modules/rpgmakerace.py index 25674a6..631d962 100644 --- a/modules/rpgmakerace.py +++ b/modules/rpgmakerace.py @@ -21,6 +21,7 @@ from tqdm import tqdm load_dotenv() openai.organization = os.getenv('org') openai.api_key = os.getenv('key') +LANGUAGE=os.getenv('language').capitalize() INPUTAPICOST = .002 # Depends on the model https://openai.com/pricing OUTPUTAPICOST = .002 @@ -200,7 +201,7 @@ def parseMap(data, filename): # Translate displayName for Map files if 'Map' in filename: - response = translateGPT(data['displayName'], 'Reply with only the english translation of the RPG location name', False) + response = translateGPT(data['displayName'], 'Reply with only the '+ LANGUAGE +' translation of the RPG location name', False) totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] data['display_name'] = response[0].replace('\"', '') @@ -242,7 +243,7 @@ def translateNote(event, regex): jaString = re.sub(r'\n', ' ', oldJAString) # Translate - response = translateGPT(jaString, 'Reply with the English translation of the note.', True) + response = translateGPT(jaString, 'Reply with the '+ LANGUAGE +' translation of the note.', True) translatedText = response[0] # Textwrap @@ -410,10 +411,10 @@ def searchThings(name, pbar): totalTokens = [0, 0] # Name - nameResponse = translateGPT(name['name'], 'Reply with only the english translation of the RPG item name.', False) if 'name' in name else '' + nameResponse = translateGPT(name['name'], 'Reply with only the '+ LANGUAGE +' translation of the RPG item name.', False) if 'name' in name else '' # Description - descriptionResponse = translateGPT(name['description'], 'Reply with only the english translation of the description.', False) if 'description' in name else '' + descriptionResponse = translateGPT(name['description'], 'Reply with only the '+ LANGUAGE +' translation of the description.', False) if 'description' in name else '' # Note if ').*)', finalJAString) if len(matchList) > 0: - response = translateGPT(matchList[0][2], 'Reply with only the english translation of the NPC name', False) + response = translateGPT(matchList[0][2], '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('.') @@ -641,7 +642,7 @@ 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 english translation of the NPC name', True) + response = translateGPT(matchList[0][1], '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('.') @@ -657,7 +658,7 @@ 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 english translation of the NPC name', True) + response = translateGPT(matchList[0][1], '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('.') @@ -684,7 +685,7 @@ def searchCodes(page, pbar): # elif 'ã€' in finalJAString: # matchList = re.findall(r'(.+?ã€(.+?)】.+?)(「.+)', finalJAString) # if len(matchList) != 0: - # response = translateGPT(matchList[0][1], 'Reply with only the english translation of the NPC name', True) + # response = translateGPT(matchList[0][1], 'Reply with only the '+ LANGUAGE +' translation of the NPC name', True) # else: # print('wtf') # totalTokens[0] += response[1][0] @@ -842,7 +843,7 @@ def searchCodes(page, pbar): for match in matchList: # Remove Textwrap match = match.replace('\\n', ' ') - response = translateGPT(match, 'Reply with the English translation.', True) + response = translateGPT(match, 'Reply with the '+ LANGUAGE +' translation.', True) translatedText = response[0] totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] @@ -996,7 +997,7 @@ def searchCodes(page, pbar): else: endString = endString.group() # Translate - response = translateGPT(jaString, 'Reply with only the english translation of the NPC name.', False) + response = translateGPT(jaString, 'Reply with only the '+ LANGUAGE +' translation of the NPC name.', False) totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] translatedText = response[0] @@ -1039,7 +1040,7 @@ def searchCodes(page, pbar): if not re.search(r'[一-é¾ ]+|[ã-ã‚”]+|[ã‚¡-ヴー]+', matchList[0]): continue - response = translateGPT(matchList[0], 'Reply with the English translation Stat Title. Keep it brief.', True) + response = translateGPT(matchList[0], 'Reply with the '+ LANGUAGE +' translation Stat Title. Keep it brief.', True) totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] translatedText = response[0] @@ -1112,7 +1113,7 @@ def searchCodes(page, pbar): # Translate if len(matchList) > 0: - response = translateGPT(matchList[0], 'Reply with the English translation of the Location Title', True) + response = translateGPT(matchList[0], 'Reply with the '+ LANGUAGE +' translation of the Location Title', True) totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] translatedText = response[0] @@ -1139,7 +1140,7 @@ def searchCodes(page, pbar): matchList = re.findall(r'Tachie showName (.+)', jaString) if len(matchList) > 0: # Translate - response = translateGPT(matchList[0], 'Reply with the English translation of the NPC name.', True) + response = translateGPT(matchList[0], 'Reply with the '+ LANGUAGE +' translation of the NPC name.', True) translatedText = response[0] totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] @@ -1197,7 +1198,7 @@ def searchCodes(page, pbar): currentGroup = [] # Translate - response = translateGPT(finalJAString, 'Reply with the English Translation.', True) + response = translateGPT(finalJAString, 'Reply with the '+ LANGUAGE +' Translation.', True) translatedText = response[0] totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] @@ -1266,7 +1267,7 @@ def searchCodes(page, pbar): jaString = re.sub(r'\n', '_', jaString) # Translate - response = translateGPT(finalJAString, 'Reply with the English Translation.', True) + response = translateGPT(finalJAString, 'Reply with the '+ LANGUAGE +' Translation.', True) translatedText = response[0] totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] @@ -1329,7 +1330,7 @@ def searchCodes(page, pbar): jaString = re.sub(r'\n', '_', jaString) # Translate - response = translateGPT(finalJAString, 'Reply with the English Translation.', True) + response = translateGPT(finalJAString, 'Reply with the '+ LANGUAGE +' Translation.', True) translatedText = response[0] totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] @@ -1434,7 +1435,7 @@ def searchCodes(page, pbar): if not re.search(r'[一-é¾ ]+|[ã-ã‚”]+|[ã‚¡-ヴー]+', jaString): continue - response = translateGPT(jaString, 'Reply with the English translation of the NPC name.', True) + response = translateGPT(jaString, 'Reply with the '+ LANGUAGE +' translation of the NPC name.', True) translatedText = response[0] totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] @@ -1491,10 +1492,10 @@ def searchSS(state, pbar): totalTokens = [0, 0] # Name - nameResponse = translateGPT(state['name'], 'Reply with only the english translation of the RPG Skill name.', True) if 'name' in state else '' + nameResponse = translateGPT(state['name'], 'Reply with only the '+ LANGUAGE +' translation of the RPG Skill name.', True) if 'name' in state else '' # Description - descriptionResponse = translateGPT(state['description'], 'Reply with only the english translation of the description.', True) if 'description' in state else '' + descriptionResponse = translateGPT(state['description'], 'Reply with only the '+ LANGUAGE +' translation of the description.', True) if 'description' in state else '' # Messages message1Response = '' @@ -1504,27 +1505,27 @@ def searchSS(state, pbar): if 'message1' in state: if len(state['message1']) > 0 and state['message1'][0] in ['ã¯', 'ã‚’', 'ã®', 'ã«', 'ãŒ']: - message1Response = translateGPT('Taro' + state['message1'], 'reply with only the gender neutral english translation of the action. Always start the sentence with Taro.', True) + message1Response = translateGPT('Taro' + state['message1'], 'reply with only the gender neutral '+ LANGUAGE +' translation of the action. Always start the sentence with Taro.', True) else: - message1Response = translateGPT(state['message1'], 'reply with only the gender neutral english translation', True) + message1Response = translateGPT(state['message1'], 'reply with only the gender neutral '+ LANGUAGE +' translation', True) if 'message2' in state: if len(state['message2']) > 0 and state['message2'][0] in ['ã¯', 'ã‚’', 'ã®', 'ã«', 'ãŒ']: - message2Response = translateGPT('Taro' + state['message2'], 'reply with only the gender neutral english translation of the action. Always start the sentence with Taro.', True) + message2Response = translateGPT('Taro' + state['message2'], 'reply with only the gender neutral '+ LANGUAGE +' translation of the action. Always start the sentence with Taro.', True) else: - message2Response = translateGPT(state['message2'], 'reply with only the gender neutral english translation', True) + message2Response = translateGPT(state['message2'], 'reply with only the gender neutral '+ LANGUAGE +' translation', True) if 'message3' in state: if len(state['message3']) > 0 and state['message3'][0] in ['ã¯', 'ã‚’', 'ã®', 'ã«', 'ãŒ']: - message3Response = translateGPT('Taro' + state['message3'], 'reply with only the gender neutral english translation of the action. Always start the sentence with Taro.', True) + message3Response = translateGPT('Taro' + state['message3'], 'reply with only the gender neutral '+ LANGUAGE +' translation of the action. Always start the sentence with Taro.', True) else: - message3Response = translateGPT(state['message3'], 'reply with only the gender neutral english translation', True) + message3Response = translateGPT(state['message3'], 'reply with only the gender neutral '+ LANGUAGE +' translation', True) if 'message4' in state: if len(state['message4']) > 0 and state['message4'][0] in ['ã¯', 'ã‚’', 'ã®', 'ã«', 'ãŒ']: - message4Response = translateGPT('Taro' + state['message4'], 'reply with only the gender neutral english translation of the action. Always start the sentence with Taro.', True) + message4Response = translateGPT('Taro' + state['message4'], 'reply with only the gender neutral '+ LANGUAGE +' translation of the action. Always start the sentence with Taro.', True) else: - message4Response = translateGPT(state['message4'], 'reply with only the gender neutral english translation', True) + message4Response = translateGPT(state['message4'], 'reply with only the gender neutral '+ LANGUAGE +' translation', True) # if 'note' in state: if 'help' in state['note']: @@ -1579,10 +1580,10 @@ def searchSystem(data, pbar): "魔力防御" == "M. Defense\ "%1 ã®%2ã‚’ç²å¾—ï¼" == "Gained %1 %2"\ "ãŠé‡‘ã‚’ %1\\G 手ã«å…¥ã‚ŒãŸï¼" == ""\ - Reply with only the english translation of the UI textbox."' + Reply with only the '+ LANGUAGE +' translation of the UI textbox."' # Title - response = translateGPT(data['gameTitle'], ' Reply with the English translation of the game title name', False) + response = translateGPT(data['gameTitle'], ' Reply with the '+ LANGUAGE +' translation of the game title name', False) totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] # data['gameTitle'] = response[0].strip('.') @@ -1602,7 +1603,7 @@ def searchSystem(data, pbar): # Armor Types for i in range(len(data['armor_types'])): - response = translateGPT(data['armorTypes'][i], 'Reply with only the english translation of the armor type', False) + response = translateGPT(data['armorTypes'][i], 'Reply with only the '+ LANGUAGE +' translation of the armor type', False) totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] data['armorTypes'][i] = response[0].replace('\"', '').strip() @@ -1610,7 +1611,7 @@ def searchSystem(data, pbar): # Skill Types for i in range(len(data['skill_types'])): - response = translateGPT(data['skillTypes'][i], 'Reply with only the english translation', False) + response = translateGPT(data['skillTypes'][i], 'Reply with only the '+ LANGUAGE +' translation', False) totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] data['skillTypes'][i] = response[0].replace('\"', '').strip() @@ -1618,7 +1619,7 @@ def searchSystem(data, pbar): # Equip Types for i in range(len(data['equip_types'])): - response = translateGPT(data['equipTypes'][i], 'Reply with only the english translation of the equipment type. No disclaimers.', False) + response = translateGPT(data['equipTypes'][i], 'Reply with only the '+ LANGUAGE +' translation of the equipment type. No disclaimers.', False) totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] data['equipTypes'][i] = response[0].replace('\"', '').strip() @@ -1626,7 +1627,7 @@ def searchSystem(data, pbar): # Variables (Optional ususally) # for i in range(len(data['variables'])): - # response = translateGPT(data['variables'][i], 'Reply with only the english translation of the title', False) + # response = translateGPT(data['variables'][i], 'Reply with only the '+ LANGUAGE +' translation of the title', False) # totalTokens[0] += response[1][0] # totalTokens[1] += response[1][1] # data['variables'][i] = response[0].replace('\"', '').strip() @@ -1635,7 +1636,7 @@ def searchSystem(data, pbar): # Messages messages = (data['terms']['messages']) for key, value in messages.items(): - response = translateGPT(value, 'Reply with only the english translation of the battle text.\nTranslate "常時ダッシュ" as "Always Dash"\nTranslate "次ã®%1ã¾ã§" as Next %1.', False) + response = translateGPT(value, 'Reply with only the '+ LANGUAGE +' translation of the battle text.\nTranslate "常時ダッシュ" as "Always Dash"\nTranslate "次ã®%1ã¾ã§" as Next %1.', False) translatedText = response[0] # Remove characters that may break scripts @@ -1793,7 +1794,7 @@ def translateGPT(t, history, fullPromptFlag): system = PROMPT user = 'Line to Translate = ' + subbedT else: - system = 'Output ONLY the english translation in the following format: `Translation: `' + system = 'Output ONLY the '+ LANGUAGE +' translation in the following format: `Translation: <'+ LANGUAGE.upper() +'_TRANSLATION>`' user = 'Line to Translate = ' + subbedT # Create Message List @@ -1824,12 +1825,12 @@ def translateGPT(t, history, fullPromptFlag): translatedText = resubVars(translatedText, varResponse[1]) # Remove Placeholder Text - translatedText = translatedText.replace('English Translation: ', '') + translatedText = translatedText.replace(LANGUAGE +' Translation: ', '') translatedText = translatedText.replace('Translation: ', '') translatedText = translatedText.replace('Line to Translate = ', '') translatedText = translatedText.replace('Translation = ', '') translatedText = translatedText.replace('Translate = ', '') - translatedText = translatedText.replace('English Translation:', '') + translatedText = translatedText.replace(LANGUAGE +' Translation:', '') translatedText = translatedText.replace('Translation:', '') translatedText = translatedText.replace('Line to Translate =', '') translatedText = translatedText.replace('Translation =', '') diff --git a/modules/rpgmakermvmz.py b/modules/rpgmakermvmz.py index b73c32d..ccd57d0 100644 --- a/modules/rpgmakermvmz.py +++ b/modules/rpgmakermvmz.py @@ -20,6 +20,7 @@ from tqdm import tqdm load_dotenv() openai.organization = os.getenv('org') openai.api_key = os.getenv('key') +LANGUAGE=os.getenv('language').capitalize() INPUTAPICOST = .002 # Depends on the model https://openai.com/pricing OUTPUTAPICOST = .002 @@ -192,7 +193,7 @@ def parseMap(data, filename): # Translate displayName for Map files if 'Map' in filename: - response = translateGPT(data['displayName'], 'Reply with only the english translation of the RPG location name', False) + response = translateGPT(data['displayName'], 'Reply with only the '+ LANGUAGE +' translation of the RPG location name', False) totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] data['displayName'] = response[0].replace('\"', '') @@ -210,7 +211,7 @@ def parseMap(data, filename): for event in events: if event is not None: # This translates ID of events. (May break the game) - # response = translateGPT(event['name'], 'Reply with the English translation of the Title.', True) + # response = translateGPT(event['name'], 'Reply with the '+ LANGUAGE +' translation of the Title.', True) # event['name'] = response[0].replace('\"', '') # totalTokens[0] += response[1][0] # totalTokens[1] += response[1][1] @@ -236,7 +237,7 @@ def translateNote(event, regex): jaString = re.sub(r'\n', ' ', oldJAString) # Translate - response = translateGPT(jaString, 'Reply with the English translation of the note.', True) + response = translateGPT(jaString, 'Reply with the '+ LANGUAGE +' translation of the note.', True) translatedText = response[0] # Textwrap @@ -412,10 +413,10 @@ def searchThings(name, pbar): return totalTokens # Name - nameResponse = translateGPT(name['name'], 'Reply with only the english translation of the RPG item name.', False) if 'name' in name else '' + nameResponse = translateGPT(name['name'], 'Reply with only the '+ LANGUAGE +' translation of the RPG item name.', False) if 'name' in name else '' # Description - descriptionResponse = translateGPT(name['description'], 'Reply with only the english translation of the description.', False) if 'description' in name else '' + descriptionResponse = translateGPT(name['description'], 'Reply with only the '+ LANGUAGE +' translation of the description.', False) if 'description' in name else '' # Note if ').*)', finalJAString) if len(matchList) > 0: - response = translateGPT(matchList[0][2], 'Reply with only the english translation of the NPC name', False) + response = translateGPT(matchList[0][2], '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('.') @@ -643,7 +644,7 @@ 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 english translation of the NPC name', False) + 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('.') @@ -659,7 +660,7 @@ 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 english translation of the NPC name', False) + 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('.') @@ -686,7 +687,7 @@ def searchCodes(page, pbar): # elif 'ã€' in finalJAString: # matchList = re.findall(r'(.+?ã€(.+?)】.+?)(「.+)', finalJAString) # if len(matchList) != 0: - # response = translateGPT(matchList[0][1], 'Reply with only the english translation of the NPC name', True) + # response = translateGPT(matchList[0][1], 'Reply with only the '+ LANGUAGE +' translation of the NPC name', True) # else: # print('wtf') # totalTokens[0] += response[1][0] @@ -844,7 +845,7 @@ def searchCodes(page, pbar): for match in matchList: # Remove Textwrap match = match.replace('\\n', ' ') - response = translateGPT(match, 'Reply with the English translation.', True) + response = translateGPT(match, 'Reply with the '+ LANGUAGE +' translation.', True) translatedText = response[0] totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] @@ -998,7 +999,7 @@ def searchCodes(page, pbar): else: endString = endString.group() # Translate - response = translateGPT(jaString, 'Reply with only the english translation of the NPC name.', False) + response = translateGPT(jaString, 'Reply with only the '+ LANGUAGE +' translation of the NPC name.', False) totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] translatedText = response[0] @@ -1041,7 +1042,7 @@ def searchCodes(page, pbar): if not re.search(r'[一-é¾ ]+|[ã-ã‚”]+|[ã‚¡-ヴー]+', matchList[0]): continue - response = translateGPT(matchList[0], 'Reply with the English translation Stat Title. Keep it brief.', True) + response = translateGPT(matchList[0], 'Reply with the '+ LANGUAGE +' translation Stat Title. Keep it brief.', True) totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] translatedText = response[0] @@ -1114,7 +1115,7 @@ def searchCodes(page, pbar): # Translate if len(matchList) > 0: - response = translateGPT(matchList[0], 'Reply with the English translation of the Location Title', True) + response = translateGPT(matchList[0], 'Reply with the '+ LANGUAGE +' translation of the Location Title', True) totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] translatedText = response[0] @@ -1140,7 +1141,7 @@ def searchCodes(page, pbar): matchList = re.findall(r'Tachie showName (.+)', jaString) if len(matchList) > 0: # Translate - response = translateGPT(matchList[0], 'Reply with the English translation of the NPC name.', False) + response = translateGPT(matchList[0], 'Reply with the '+ LANGUAGE +' translation of the NPC name.', False) translatedText = response[0] totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] @@ -1198,7 +1199,7 @@ def searchCodes(page, pbar): currentGroup = [] # Translate - response = translateGPT(finalJAString, 'Reply with the English Translation.', True) + response = translateGPT(finalJAString, 'Reply with the '+ LANGUAGE +' Translation.', True) translatedText = response[0] totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] @@ -1267,7 +1268,7 @@ def searchCodes(page, pbar): jaString = re.sub(r'\n', '_', jaString) # Translate - response = translateGPT(finalJAString, 'Reply with the English Translation.', True) + response = translateGPT(finalJAString, 'Reply with the '+ LANGUAGE +' Translation.', True) translatedText = response[0] totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] @@ -1330,7 +1331,7 @@ def searchCodes(page, pbar): jaString = re.sub(r'\n', '_', jaString) # Translate - response = translateGPT(finalJAString, 'Reply with the English Translation.', True) + response = translateGPT(finalJAString, 'Reply with the '+ LANGUAGE +' Translation.', True) translatedText = response[0] totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] @@ -1435,7 +1436,7 @@ def searchCodes(page, pbar): if not re.search(r'[一-é¾ ]+|[ã-ã‚”]+|[ã‚¡-ヴー]+', jaString): continue - response = translateGPT(jaString, 'Reply with the English translation of the NPC name.', False) + response = translateGPT(jaString, 'Reply with the '+ LANGUAGE +' translation of the NPC name.', False) translatedText = response[0] totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] @@ -1492,10 +1493,10 @@ def searchSS(state, pbar): totalTokens = [0, 0] # Name - nameResponse = translateGPT(state['name'], 'Reply with only the english translation of the RPG Skill name.', True) if 'name' in state else '' + nameResponse = translateGPT(state['name'], 'Reply with only the '+ LANGUAGE +' translation of the RPG Skill name.', True) if 'name' in state else '' # Description - descriptionResponse = translateGPT(state['description'], 'Reply with only the english translation of the description.', True) if 'description' in state else '' + descriptionResponse = translateGPT(state['description'], 'Reply with only the '+ LANGUAGE +' translation of the description.', True) if 'description' in state else '' # Messages message1Response = '' @@ -1505,27 +1506,27 @@ def searchSS(state, pbar): if 'message1' in state: if len(state['message1']) > 0 and state['message1'][0] in ['ã¯', 'ã‚’', 'ã®', 'ã«', 'ãŒ']: - message1Response = translateGPT('Taro' + state['message1'], 'reply with only the gender neutral english translation of the action. Always start the sentence with Taro.', True) + message1Response = translateGPT('Taro' + state['message1'], 'reply with only the gender neutral '+ LANGUAGE +' translation of the action. Always start the sentence with Taro.', True) else: - message1Response = translateGPT(state['message1'], 'reply with only the gender neutral english translation', True) + message1Response = translateGPT(state['message1'], 'reply with only the gender neutral '+ LANGUAGE +' translation', True) if 'message2' in state: if len(state['message2']) > 0 and state['message2'][0] in ['ã¯', 'ã‚’', 'ã®', 'ã«', 'ãŒ']: - message2Response = translateGPT('Taro' + state['message2'], 'reply with only the gender neutral english translation of the action. Always start the sentence with Taro.', True) + message2Response = translateGPT('Taro' + state['message2'], 'reply with only the gender neutral '+ LANGUAGE +' translation of the action. Always start the sentence with Taro.', True) else: - message2Response = translateGPT(state['message2'], 'reply with only the gender neutral english translation', True) + message2Response = translateGPT(state['message2'], 'reply with only the gender neutral '+ LANGUAGE +' translation', True) if 'message3' in state: if len(state['message3']) > 0 and state['message3'][0] in ['ã¯', 'ã‚’', 'ã®', 'ã«', 'ãŒ']: - message3Response = translateGPT('Taro' + state['message3'], 'reply with only the gender neutral english translation of the action. Always start the sentence with Taro.', True) + message3Response = translateGPT('Taro' + state['message3'], 'reply with only the gender neutral '+ LANGUAGE +' translation of the action. Always start the sentence with Taro.', True) else: - message3Response = translateGPT(state['message3'], 'reply with only the gender neutral english translation', True) + message3Response = translateGPT(state['message3'], 'reply with only the gender neutral '+ LANGUAGE +' translation', True) if 'message4' in state: if len(state['message4']) > 0 and state['message4'][0] in ['ã¯', 'ã‚’', 'ã®', 'ã«', 'ãŒ']: - message4Response = translateGPT('Taro' + state['message4'], 'reply with only the gender neutral english translation of the action. Always start the sentence with Taro.', True) + message4Response = translateGPT('Taro' + state['message4'], 'reply with only the gender neutral '+ LANGUAGE +' translation of the action. Always start the sentence with Taro.', True) else: - message4Response = translateGPT(state['message4'], 'reply with only the gender neutral english translation', True) + message4Response = translateGPT(state['message4'], 'reply with only the gender neutral '+ LANGUAGE +' translation', True) # if 'note' in state: if 'help' in state['note']: @@ -1580,10 +1581,10 @@ def searchSystem(data, pbar): "魔力防御" == "M. Defense\ "%1 ã®%2ã‚’ç²å¾—ï¼" == "Gained %1 %2"\ "ãŠé‡‘ã‚’ %1\\G 手ã«å…¥ã‚ŒãŸï¼" == ""\ - Reply with only the english translation of the UI textbox."' + Reply with only the '+ LANGUAGE +' translation of the UI textbox."' # Title - response = translateGPT(data['gameTitle'], ' Reply with the English translation of the game title name', False) + response = translateGPT(data['gameTitle'], ' Reply with the '+ LANGUAGE +' translation of the game title name', False) totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] data['gameTitle'] = response[0].strip('.') @@ -1603,7 +1604,7 @@ def searchSystem(data, pbar): # Armor Types for i in range(len(data['armorTypes'])): - response = translateGPT(data['armorTypes'][i], 'Reply with only the english translation of the armor type', False) + response = translateGPT(data['armorTypes'][i], 'Reply with only the '+ LANGUAGE +' translation of the armor type', False) totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] data['armorTypes'][i] = response[0].replace('\"', '').strip() @@ -1611,7 +1612,7 @@ def searchSystem(data, pbar): # Skill Types for i in range(len(data['skillTypes'])): - response = translateGPT(data['skillTypes'][i], 'Reply with only the english translation', False) + response = translateGPT(data['skillTypes'][i], 'Reply with only the '+ LANGUAGE +' translation', False) totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] data['skillTypes'][i] = response[0].replace('\"', '').strip() @@ -1619,7 +1620,7 @@ def searchSystem(data, pbar): # Equip Types for i in range(len(data['equipTypes'])): - response = translateGPT(data['equipTypes'][i], 'Reply with only the english translation of the equipment type. No disclaimers.', False) + response = translateGPT(data['equipTypes'][i], 'Reply with only the '+ LANGUAGE +' translation of the equipment type. No disclaimers.', False) totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] data['equipTypes'][i] = response[0].replace('\"', '').strip() @@ -1627,7 +1628,7 @@ def searchSystem(data, pbar): # Variables (Optional ususally) # for i in range(len(data['variables'])): - # response = translateGPT(data['variables'][i], 'Reply with only the english translation of the title', False) + # response = translateGPT(data['variables'][i], 'Reply with only the '+ LANGUAGE +' translation of the title', False) # totalTokens[0] += response[1][0] # totalTokens[1] += response[1][1] # data['variables'][i] = response[0].replace('\"', '').strip() @@ -1636,7 +1637,7 @@ def searchSystem(data, pbar): # Messages messages = (data['terms']['messages']) for key, value in messages.items(): - response = translateGPT(value, 'Reply with only the english translation of the battle text.\nTranslate "常時ダッシュ" as "Always Dash"\nTranslate "次ã®%1ã¾ã§" as Next %1.', False) + response = translateGPT(value, 'Reply with only the '+ LANGUAGE +' translation of the battle text.\nTranslate "常時ダッシュ" as "Always Dash"\nTranslate "次ã®%1ã¾ã§" as Next %1.', False) translatedText = response[0] # Remove characters that may break scripts @@ -1795,7 +1796,7 @@ def translateGPT(t, history, fullPromptFlag): system = PROMPT user = 'Line to Translate = ' + subbedT else: - system = 'Output ONLY the english translation in the following format: `Translation: `' + system = 'Output ONLY the '+ LANGUAGE +' translation in the following format: `Translation: <'+ LANGUAGE.upper() +'_TRANSLATION>`' user = 'Line to Translate = ' + subbedT # Create Message List @@ -1826,12 +1827,12 @@ def translateGPT(t, history, fullPromptFlag): translatedText = resubVars(translatedText, varResponse[1]) # Remove Placeholder Text - translatedText = translatedText.replace('English Translation: ', '') + translatedText = translatedText.replace(LANGUAGE +' Translation: ', '') translatedText = translatedText.replace('Translation: ', '') translatedText = translatedText.replace('Line to Translate = ', '') translatedText = translatedText.replace('Translation = ', '') translatedText = translatedText.replace('Translate = ', '') - translatedText = translatedText.replace('English Translation:', '') + translatedText = translatedText.replace(LANGUAGE +' Translation:', '') translatedText = translatedText.replace('Translation:', '') translatedText = translatedText.replace('Line to Translate =', '') translatedText = translatedText.replace('Translation =', '') diff --git a/modules/txt.py b/modules/txt.py index 05f58de..c263286 100644 --- a/modules/txt.py +++ b/modules/txt.py @@ -20,6 +20,7 @@ from tqdm import tqdm load_dotenv() openai.organization = os.getenv('org') openai.api_key = os.getenv('key') +LANGUAGE=os.getenv('language').capitalize() APICOST = .002 # Depends on the model https://openai.com/pricing PROMPT = Path('prompt.txt').read_text(encoding='utf-8') @@ -332,7 +333,7 @@ def translateGPT(t, history, fullPromptFlag): system = PROMPT user = 'Line to Translate = ' + subbedT else: - system = 'Output ONLY the english translation in the following format: `Translation: `' + system = 'Output ONLY the '+ LANGUAGE +' translation in the following format: `Translation: <'+ LANGUAGE.upper() +'_TRANSLATION>`' user = 'Line to Translate = ' + subbedT # Create Message List @@ -363,12 +364,12 @@ def translateGPT(t, history, fullPromptFlag): translatedText = resubVars(translatedText, varResponse[1]) # Remove Placeholder Text - translatedText = translatedText.replace('English Translation: ', '') + translatedText = translatedText.replace(LANGUAGE +' Translation: ', '') translatedText = translatedText.replace('Translation: ', '') translatedText = translatedText.replace('Line to Translate = ', '') translatedText = translatedText.replace('Translation = ', '') translatedText = translatedText.replace('Translate = ', '') - translatedText = translatedText.replace('English Translation:', '') + translatedText = translatedText.replace(LANGUAGE +' Translation:', '') translatedText = translatedText.replace('Translation:', '') translatedText = translatedText.replace('Line to Translate =', '') translatedText = translatedText.replace('Translation =', '') diff --git a/modules/tyrano.py b/modules/tyrano.py index 97b0b41..2398ae7 100644 --- a/modules/tyrano.py +++ b/modules/tyrano.py @@ -18,6 +18,7 @@ from tqdm import tqdm load_dotenv() openai.organization = os.getenv('org') openai.api_key = os.getenv('key') +LANGUAGE=os.getenv('language').capitalize() APICOST = .002 # Depends on the model https://openai.com/pricing PROMPT = Path('prompt.txt').read_text(encoding='utf-8') @@ -127,7 +128,7 @@ def translateTyrano(data, pbar): if '#' in data[i]: matchList = re.findall(r'#(.+)', data[i]) if len(matchList) != 0: - response = translateGPT(matchList[0], 'Reply with only the english translation of the NPC name', True) + response = translateGPT(matchList[0], 'Reply with only the '+ LANGUAGE +' translation of the NPC name', True) speaker = response[0] tokens += response[1] data[i] = '#' + speaker + '\n' @@ -499,7 +500,7 @@ def translateGPT(t, history, fullPromptFlag): system = PROMPT user = 'Line to Translate = ' + subbedT else: - system = 'Output ONLY the english translation in the following format: `Translation: `' + system = 'Output ONLY the '+ LANGUAGE +' translation in the following format: `Translation: <'+ LANGUAGE.upper() +'_TRANSLATION>`' user = 'Line to Translate = ' + subbedT # Create Message List @@ -530,12 +531,12 @@ def translateGPT(t, history, fullPromptFlag): translatedText = resubVars(translatedText, varResponse[1]) # Remove Placeholder Text - translatedText = translatedText.replace('English Translation: ', '') + translatedText = translatedText.replace(LANGUAGE +' Translation: ', '') translatedText = translatedText.replace('Translation: ', '') translatedText = translatedText.replace('Line to Translate = ', '') translatedText = translatedText.replace('Translation = ', '') translatedText = translatedText.replace('Translate = ', '') - translatedText = translatedText.replace('English Translation:', '') + translatedText = translatedText.replace(LANGUAGE +' Translation:', '') translatedText = translatedText.replace('Translation:', '') translatedText = translatedText.replace('Line to Translate =', '') translatedText = translatedText.replace('Translation =', '')