Spaces:
Paused
Paused
Update src/main.py
Browse files- src/main.py +11 -5
src/main.py
CHANGED
@@ -91,7 +91,7 @@ def translate_korean_text(text):
|
|
91 |
"sl": "ko",
|
92 |
"tl": "en",
|
93 |
"dt": "t",
|
94 |
-
"q": text.replace(f"'{quoted_word}'", "
|
95 |
}
|
96 |
response = requests.get(url, params=params)
|
97 |
if response.status_code != 200:
|
@@ -100,7 +100,8 @@ def translate_korean_text(text):
|
|
100 |
translated_text = ' '.join(item[0] for item in response.json()[0] if item[0])
|
101 |
|
102 |
# 3. 따옴표 안의 단어 처리
|
103 |
-
|
|
|
104 |
proper_noun = quoted_word.upper()
|
105 |
else: # 한글 단어인 경우
|
106 |
params["q"] = quoted_word
|
@@ -111,9 +112,14 @@ def translate_korean_text(text):
|
|
111 |
proper_noun = quoted_word.upper()
|
112 |
|
113 |
# 4. 최종 문장 조합
|
114 |
-
|
115 |
-
|
116 |
-
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
return final_text
|
119 |
|
|
|
91 |
"sl": "ko",
|
92 |
"tl": "en",
|
93 |
"dt": "t",
|
94 |
+
"q": text.replace(f"'{quoted_word}'", "XXXXX") # 특수한 마커로 대체
|
95 |
}
|
96 |
response = requests.get(url, params=params)
|
97 |
if response.status_code != 200:
|
|
|
100 |
translated_text = ' '.join(item[0] for item in response.json()[0] if item[0])
|
101 |
|
102 |
# 3. 따옴표 안의 단어 처리
|
103 |
+
# 영어 단어이거나 대문자로 된 단어는 그대로 유지
|
104 |
+
if re.match(r'^[A-Z]+$', quoted_word) or re.match(r'^[A-Za-z]+$', quoted_word):
|
105 |
proper_noun = quoted_word.upper()
|
106 |
else: # 한글 단어인 경우
|
107 |
params["q"] = quoted_word
|
|
|
112 |
proper_noun = quoted_word.upper()
|
113 |
|
114 |
# 4. 최종 문장 조합
|
115 |
+
# XXXXX를 따옴표로 묶은 proper_noun으로 대체
|
116 |
+
final_text = translated_text.replace("XXXXX", f"'{proper_noun}'")
|
117 |
+
|
118 |
+
# 불필요한 대문자 변환 방지
|
119 |
+
final_text = re.sub(r'\bNAME\b', 'name', final_text)
|
120 |
+
|
121 |
+
# 마침표 처리
|
122 |
+
final_text = final_text.replace(" .", ".")
|
123 |
|
124 |
return final_text
|
125 |
|