Hi, this is Ken has.
I tried translating using the Python package googletrans and it was so easy that I wrote it down.
If you use google translate in python [Google Translate API](https://cloud.google.com/translate/?hl=ja&utm_source=google&utm_medium=cpc&utm_campaign=japac-JP-all-ja-dr-bkws-all-super- trial-e-dr-1008074 & utm_content = text-ad-none-none-DEV_c-CRE_314712311019-ADGP_Hybrid +% 7C + AW + SEM +% 7C + BKWS + ~ + T1 +% 7C + EXA +% 7C + ML +% 7C + 1: 1 +% 7C + JP +% 7C + ja +% 7C + Translation +% 7C + google + translator + api +% 7C + en-KWID_43700031334293414-kwd-74703397964 & userloc_1009241 & utm_term = KW_google% 20translator% 20api & gclid = EAIaIQobChMIk-7p49DzA
You might think, but this costs money, doesn't it? It's a secret story, but I wanted to use Google Translate from python as if it were playful without spending money.
After researching various things, I found something called googletrans, so I decided to use it.
Roughly like this. Let's start by installing the package.
Just type the following command into the console and press Enter.
pip install googletrans
Super easy.
trans.py
from googletrans import Translator
str = 'This is a banana.' #Characters you want to translate
translator = Translator()
trans_text = translator.translate(str) #Convert to English by default
print(trans_text.text)
The basic usage is like this.
It is also possible to specify the translation destination language by adding an option at translate (str)
.
trans.py
from googletrans import Translator
str = 'This is a banana.' #Characters you want to translate
translator = Translator()
trans_text = translator.translate(str,src='ja',dest='de') #Convert from Japanese to German
print(trans_text.text)
Roughly, I introduced the Python package "googletrans" that can use Google Translate. As a feature
Is it like this? that's all.
Recommended Posts