728x90
๋ฐ์ํ
โป SK ์ด๋์ค ๋ฃจํค์ฆ 24๊ธฐ (ํด๋ผ์ฐ๋๊ธฐ๋ฐ ์ค๋งํธ ์ตํฉ๋ณด์ ๊ณผ์ ) ๊ต์ก์ ๋ค์ผ๋ฉด์ ์์ฑํ ๋ด์ฉ์ ๋๋ค.
1๏ธโฃ googletrans ๋ผ์ด๋ธ๋ฌ๋ฆฌ
Google Translate API๋ฅผ ์ฌ์ฉํ์ฌ ํ ์คํธ๋ฅผ ๋ฒ์ญํ ์ ์๋ ํ์ด์ฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
๊ฐ๋จํ ์ฝ๋๋ก ๋ค๊ตญ์ด ๋ฒ์ญ ๊ธฐ๋ฅ์ ์ ๊ณต
๐น ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค์น
pip install googletrans==3.1.0a0
2๏ธโฃ ๊ฐ๋จํ ๋ฒ์ญ๊ธฐ ์์
๐น ์์ 1) ์ค๋ฅ ๋ฐ์ํจ โ
import googletrans
translator = googletrans.Translator()
# ์
๋ ฅ
input_text = input("ํ๊ธ์ ์
๋ ฅํ์ธ์: ")
# ๋ฒ์ญ
translated = translator.translate(input_text, dest='en')
# ์ถ๋ ฅ
print(f"์
๋ ฅํ ํ๊ธ: {input_text}")
print(f"๋ฒ์ญ๋ ์์ด: {translated}")
โผ ์ค๋ฅ ํด๊ฒฐ ๋ฐฉ๋ฒ
[์ค๋ฅ ํด๊ฒฐ] googletrans ์ฌ์ฉ ์ค ์ค๋ฅ (ModuleNotFoundError: No module named 'cgi')
๐ 1. ์ค๋ฅ ์ํฉ๋ฐ์ ํ๊ฒฝ: {Windows11, Python3.xxx/googletrans, vscode}์ค๋ฅ ์ฝ๋: ModuleNotFoundError: No module named 'cgi'import googletrans...์๋ฌ ๋ฉ์์ง: Traceback (most recent call last): import httpx File "c:\Users\user\AppData
dev-with-wish.tistory.com
๐น ์์ 2) ์ค๋ฅ ํด๊ฒฐ ํ ์ฝ๋
from deep_translator import GoogleTranslator
# ์
๋ ฅ
input_text = input("ํ๊ธ์ ์
๋ ฅํ์ธ์: ")
# ๋ฒ์ญ
translated = GoogleTranslator(source='ko', target='en').translate(input_text)
# ์ถ๋ ฅ
print(f"์
๋ ฅํ ํ๊ธ: {input_text}")
print(f"๋ฒ์ญ๋ ์์ด: {translated}")
- ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๊ฐ์ ธ์ค๊ธฐ
from deep_translator import GoogleTranslator
๋deep-translator
๋ผ์ด๋ธ๋ฌ๋ฆฌ์์Google Translator
๊ธฐ๋ฅ์ ๊ฐ์ ธ์ต๋๋ค. - ๋ฒ์ญ ๊ฐ์ฒด ์์ฑ
GoogleTranslator(source='ko', target='en')
๋ ํ๊ตญ์ด(ko
)๋ฅผ ์์ด(en
)๋ก ๋ฒ์ญํ๋ ์ค์ ์ ๋๋ค. - ๋ฒ์ญ ์ํ
.translate(input_text)
๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ ์ ๋ ฅ๋ ํ ์คํธ๋ฅผ ๋ฒ์ญํฉ๋๋ค.
728x90
๋ฐ์ํ
'๐งฉ Language > Python' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Python] ์ฃผ์ ๋ฐ์ดํฐ ๊ตฌ์กฐ (๋ฆฌ์คํธ / ๋์ ๋๋ฆฌ) (0) | 2025.01.14 |
---|---|
[Python] ๊ธฐ๋ณธ ์ ์ถ๋ ฅ ๋ค๋ฃจ๊ธฐ (0) | 2025.01.13 |
[์ค๋ฅ ํด๊ฒฐ] googletrans ์ฌ์ฉ ์ค ์ค๋ฅ (0) | 2025.01.13 |
[Python] ๊ธฐ๋ณธ ๋ฌธ๋ฒ (๋ณ์ / ๋ฐ์ดํฐ ํ์ / ๋ณ์ ๋ค์ด๋ฐ ๊ท์น) (0) | 2025.01.13 |
Windows 11 ํ์ด์ฌ ๊ฐ๋ฐ ํ๊ฒฝ ์ค์ (Visual Studio Code ์ฌ์ฉ) (0) | 2025.01.13 |