Exception for Client

This commit is contained in:
dazedanon 2025-07-12 14:29:23 -05:00
parent 08611a38b2
commit 7fd7258800
2 changed files with 40 additions and 30 deletions

View file

@ -549,10 +549,11 @@ def searchNames(data, pbar, context):
(r"<PE拡張:(.*?)>", False),
(r"<hint:(.*?)>", False),
(r"<SGDescription:(.*?)>", False),
(r"<SG説明:\n?(.*?)>", False),
(r"<SG説明:\n?(.*?)>", True),
(r"<SG説明2:\n?(.*?)>", False),
(r"<SG説明3:\n?(.*?)>", False),
(r"<SG説明4:\n?(.*?)>", False),
(r"<SG説明:.+?Client\s?:.+?\n\n(.*?)>", True),
(r"<SGカテゴリ:(.*?)>", False),
(r"<Switch Shop Description>\n(.*)\n", False),
(r"<MapText:(.*?)>", False),
@ -576,10 +577,19 @@ def searchNames(data, pbar, context):
note = entry["note"]
for regex, wordwrap in note_regexes:
matches = re.findall(regex, note, re.DOTALL)
for m in matches:
match_text = m if isinstance(m, str) else m[0]
notesBatch.append(match_text)
notesBatchMap.append((idx, regex, match_text, wordwrap))
# Special filter for <SG説明:...> to skip if 'Client' is in the match
if regex.startswith(r"<SG説明:"):
for m in matches:
match_text = m if isinstance(m, str) else m[0]
if "Client:" in match_text or "Client :":
continue
notesBatch.append(match_text)
notesBatchMap.append((idx, regex, match_text, wordwrap))
else:
for m in matches:
match_text = m if isinstance(m, str) else m[0]
notesBatch.append(match_text)
notesBatchMap.append((idx, regex, match_text, wordwrap))
# --- Batch translate all notes ---
translatedNotesBatch = []

View file

@ -29,28 +29,28 @@ def wrapText(text: str, width: int) -> str:
"""
if not text:
return ""
words = text.split()
lines = []
current_line = []
current_length = 0
for word in words:
# Calculate visible length ignoring color codes
word_length = _get_visible_length(word)
# Check if adding this word would exceed the width
if current_length + word_length + len(current_line) <= width:
current_line.append(word)
current_length += word_length
else:
if current_line: # Only add line if we have words
lines.append(" ".join(current_line))
current_line = [word]
current_length = word_length
# Add the last line if it has any words
if current_line:
lines.append(" ".join(current_line))
return "\n".join(lines)
# Split on double newlines (\n\n or \\n\\n)
import re
segments = re.split(r'(?:\n\n|\\n\\n)', text)
wrapped_segments = []
for segment in segments:
words = segment.split()
lines = []
current_line = []
current_length = 0
for word in words:
word_length = _get_visible_length(word)
if current_length + word_length + len(current_line) <= width:
current_line.append(word)
current_length += word_length
else:
if current_line:
lines.append(" ".join(current_line))
current_line = [word]
current_length = word_length
if current_line:
lines.append(" ".join(current_line))
wrapped_segments.append("\n".join(lines))
# Rejoin with double newlines to preserve hard breaks
return "\n\n".join(wrapped_segments)