Translate to Different Languages

This commit is contained in:
m5kro 2023-11-17 13:04:46 -08:00
parent 7fa94430a0
commit 722aa25077
11 changed files with 152 additions and 145 deletions

View file

@ -1,2 +1,4 @@
key="<OPEN_AI_KEY>"
organization="<ORG_KEY>"
#The language to translate TO, Don't forget to change the prompt
language="<LANGUAGE_NAME>"

View file

@ -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'[<EFBFBD><EFBFBD>-<2D>]+|[<5B><>-?]+|[<5B>@-<2D><>]+|[\uFF00-\uFFEF]', subbedT):
return (t, 0)
# Characters
context = '```\
Game Characters:\
Character: 池ノ上 拓海 == Ikenoue Takumi - Gender: Male\
Character: 福永 こはる == Fukunaga Koharu - Gender: Female\
Character: 神泉 理央 == Kamiizumi Rio - Gender: Female\
Character: 吉祥寺 アリサ == Kisshouji Arisa - Gender: Female\
Character: 久我 友里子 == Kuga Yuriko - Gender: Female\
Character: <EFBFBD>r<EFBFBD>m<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>C == Ikenoue Takumi - Gender: Male\
Character: <EFBFBD><EFBFBD><EFBFBD>i <EFBFBD><EFBFBD><EFBFBD>͂<EFBFBD> == Fukunaga Koharu - Gender: Female\
Character: <EFBFBD>_<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> == Kamiizumi Rio - Gender: Female\
Character: <EFBFBD>g<EFBFBD>ˎ<EFBFBD> <EFBFBD>A<EFBFBD><EFBFBD><EFBFBD>T == Kisshouji Arisa - Gender: Female\
Character: <EFBFBD>v<EFBFBD><EFBFBD> <EFBFBD>F<EFBFBD><EFBFBD><EFBFBD>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: <ENGLISH_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('<EFBFBD><EFBFBD>', '')
# Return Translation
if len(translatedText) > 15 * len(t) or "I'm sorry, but I'm unable to assist with that translation" in translatedText:

View file

@ -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: <ENGLISH_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 =', '')

View file

@ -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: <ENGLISH_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 =', '')

View file

@ -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: <ENGLISH_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 =', '')

View file

@ -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: <ENGLISH_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 =', '')

View file

@ -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: <ENGLISH_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 =', '')

View file

@ -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 '<SG説明:' in name['note']:
@ -448,24 +449,24 @@ def searchNames(name, pbar, context):
# Set the context of what we are translating
if 'Actors' in context:
newContext = 'Reply with only the english translation of the NPC name'
newContext = 'Reply with only the '+ LANGUAGE +' translation of the NPC name'
if 'Armors' in context:
newContext = 'Reply with only the english 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 english 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 english 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 english 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 english translation of the RPG weapon name'
newContext = 'Reply with only the '+ LANGUAGE +' translation of the RPG weapon name'
# Extract Data
responseList = []
responseList.append(translateGPT(name['name'], newContext, True))
if 'Actors' in context:
responseList.append(translateGPT(name['description'], '', True))
responseList.append(translateGPT(name['nickname'], 'Reply with ONLY the english translation of the NPC nickname', True))
responseList.append(translateGPT(name['nickname'], 'Reply with ONLY the '+ LANGUAGE +' translation of the NPC nickname', True))
if 'Armors' in context or 'Weapons' in context:
if 'description' in name:
@ -592,7 +593,7 @@ def searchCodes(page, pbar):
# Color Regex: ^([\\]+[cC]\[[0-9]\]+(.+?)[\\]+[cC]\[[0]\])
matchList = re.findall(r'(.*?([\\]+[nN]<(.+?)>).*)', 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: <ENGLISH_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 =', '')

View file

@ -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 '<SG説明:' in name['note']:
@ -450,24 +451,24 @@ def searchNames(name, pbar, context):
# Set the context of what we are translating
if 'Actors' in context:
newContext = 'Reply with only the english translation of the NPC name'
newContext = 'Reply with only the '+ LANGUAGE +' translation of the NPC name'
if 'Armors' in context:
newContext = 'Reply with only the english 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 english 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 english 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 english 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 english translation of the RPG weapon name'
newContext = 'Reply with only the '+ LANGUAGE +' translation of the RPG weapon name'
# Extract Data
responseList = []
responseList.append(translateGPT(name['name'], newContext, True))
if 'Actors' in context:
responseList.append(translateGPT(name['profile'], '', True))
responseList.append(translateGPT(name['nickname'], 'Reply with ONLY the english translation of the NPC nickname', True))
responseList.append(translateGPT(name['nickname'], 'Reply with ONLY the '+ LANGUAGE +' translation of the NPC nickname', True))
if 'Armors' in context or 'Weapons' in context:
if 'description' in name:
@ -594,7 +595,7 @@ def searchCodes(page, pbar):
# Color Regex: ^([\\]+[cC]\[[0-9]\]+(.+?)[\\]+[cC]\[[0]\])
matchList = re.findall(r'(.*?([\\]+[nN]<(.+?)>).*)', 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: <ENGLISH_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 =', '')

View file

@ -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: <ENGLISH_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 =', '')

View file

@ -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: <ENGLISH_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 =', '')