fix: 이미지삭제(unwanted_words) 설정 누락 버그 수정 및 치환 로직 최적화
- ImageProcessor3.update_toggle_states에서 unwanted_words 설정이 갱신되지 않던 문제 해결 - process_translated_texts 함수 내 텍스트 치환 로직을 파이썬 내장 .replace()를 사용하도록 개선하여 다중 단어 처리 및 성능 향상
This commit is contained in:
parent
0e43590ab5
commit
19f2892ac0
|
|
@ -448,6 +448,9 @@ class ImageProcessor3:
|
|||
def update_toggle_states(self, toggle_states):
|
||||
self.toggle_states = toggle_states
|
||||
|
||||
if 'unwanted_words' in self.toggle_states:
|
||||
self.unwanted_texts = self.toggle_states['unwanted_words']
|
||||
|
||||
# 1. 멤버십 및 권한 정보 업데이트
|
||||
self.is_member_valid = self.toggle_states.get('membership_level', 'basic') == 'vip' or self.authenticated_by_admin
|
||||
|
||||
|
|
@ -1499,52 +1502,27 @@ class ImageProcessor3:
|
|||
|
||||
def process_translated_texts(self, translated_texts, local_image_path, index):
|
||||
"""
|
||||
번역된 단어 리스트(translated_texts)에서 unwanted_texts의 원본값이
|
||||
앞이나 뒤에 포함되면 치환값으로 바꿉니다.
|
||||
번역된 텍스트 리스트(translated_texts)에서 unwanted_texts의 원본값이
|
||||
포함되면 치환값으로 바꿉니다.
|
||||
치환값이 '이미지삭제'라면 None 반환(이미지 제외)
|
||||
"""
|
||||
new_texts = []
|
||||
for i, text in enumerate(translated_texts):
|
||||
self.logger.log(f"[치환 처리 {i+1}] 원본 텍스트: '{text}'", level=logging.DEBUG)
|
||||
|
||||
# 텍스트를 빈칸으로 분리
|
||||
words = text.split()
|
||||
self.logger.log(f"[치환 처리 {i+1}] 분리된 단어: {words}", level=logging.DEBUG)
|
||||
|
||||
processed_words = []
|
||||
final_text = text
|
||||
text_replaced = False
|
||||
|
||||
for word_idx, word in enumerate(words):
|
||||
word_replaced = False
|
||||
|
||||
# unwanted_texts와 매칭 확인
|
||||
if isinstance(self.unwanted_texts, dict) and self.unwanted_texts:
|
||||
for origin, replace in self.unwanted_texts.items():
|
||||
if word.startswith(origin) or word.endswith(origin) or word == origin:
|
||||
self.logger.log(f"[치환 처리 {i+1}] 단어 '{word}' -> '{replace}' (원본: '{origin}')", level=logging.DEBUG)
|
||||
|
||||
if origin in final_text:
|
||||
if replace == "이미지삭제":
|
||||
self.logger.log(f"이미지 {index+1} 제외됨: {local_image_path}", level=logging.DEBUG)
|
||||
self.logger.log(f"이미지 {index+1} 제외됨 (키워드 '{origin}' 감지): {local_image_path}", level=logging.DEBUG)
|
||||
return None
|
||||
|
||||
# 단어 치환
|
||||
if word == origin:
|
||||
new_word = replace
|
||||
elif word.startswith(origin):
|
||||
new_word = replace + word[len(origin):]
|
||||
elif word.endswith(origin):
|
||||
new_word = word[:-len(origin)] + replace
|
||||
|
||||
processed_words.append(new_word)
|
||||
word_replaced = True
|
||||
final_text = final_text.replace(origin, replace)
|
||||
text_replaced = True
|
||||
self.logger.log(f"[치환 처리 {i+1}] 단어 치환 완료: '{word}' -> '{new_word}'", level=logging.DEBUG)
|
||||
break
|
||||
|
||||
if not word_replaced:
|
||||
processed_words.append(word)
|
||||
|
||||
# 처리된 단어들을 다시 합치기
|
||||
final_text = ' '.join(processed_words)
|
||||
new_texts.append(final_text)
|
||||
|
||||
if text_replaced:
|
||||
|
|
|
|||
Loading…
Reference in New Issue