We can do better
This commit is contained in:
parent
677d23e371
commit
e333e4a51d
1 changed files with 9 additions and 3 deletions
|
|
@ -203,11 +203,11 @@ def translateRegex(data, filename, translatedList):
|
|||
i = 0
|
||||
|
||||
# Define regex patterns outside loop
|
||||
dialogueRegex = r'\"text\":\s?\"(.+)\",'
|
||||
lineRegexSpeaker = r'"name":\s?"(.+)",'
|
||||
choiceRegex = r"\$menu_item.+?,(.*?),"
|
||||
titleRegex = r"title\s'(.*)'$"
|
||||
setgamedatatitleRegex = r'\\setgamedatatitle\("(.+?)"\)'
|
||||
dlgRegex = r'\"text\":\s?\"(.+)\",'
|
||||
selRegex = r'\\sel\((.+)\)'
|
||||
|
||||
while i < len(data):
|
||||
|
|
@ -259,11 +259,14 @@ def translateRegex(data, filename, translatedList):
|
|||
tokens[1] += response[1][1]
|
||||
data[i] = data[i].replace(match.group(1), speaker)
|
||||
|
||||
# Dlg (JSON text field)
|
||||
match = re.search(dlgRegex, data[i])
|
||||
# Dialogue (JSON text field)
|
||||
match = re.search(dialogueRegex, data[i])
|
||||
if match:
|
||||
jaString = match.group(1)
|
||||
|
||||
# Replace \n with > for translation
|
||||
jaString = jaString.replace('\\n', '>')
|
||||
|
||||
# Pass 1 - Collect for batch translation
|
||||
if not translatedList:
|
||||
# Add with speaker prefix if available
|
||||
|
|
@ -287,6 +290,9 @@ def translateRegex(data, filename, translatedList):
|
|||
|
||||
# Remove speaker prefix from translation
|
||||
translatedText = re.sub(r"^\[?(.+?)\]?\s?[|:]\s?", "", translatedText)
|
||||
|
||||
# Convert > back to \n
|
||||
translatedText = translatedText.replace('>', '\\n')
|
||||
|
||||
# Escape Quotes
|
||||
translatedText = translatedText.replace('"', '\\"')
|
||||
|
|
|
|||
Loading…
Reference in a new issue