I tried using Google Translate from Python and it was just too easy

Hi, this is Ken has.

I tried translating using the Python package googletrans and it was so easy that I wrote it down.

What is googletrans

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.

Features of googletrans

Roughly like this. Let's start by installing the package.

Install googletrans

Just type the following command into the console and press Enter.

pip install googletrans

Super easy.

Try translating using googletrans

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)

It seems that you can also pass a list to the character string you want to translate. > ``` >>> translations = translator.translate(['The quick brown fox', 'jumps over', 'the lazy dog'], dest='ko') >>> for translation in translations: ... print(translation.origin, ' -> ', translation.text) # The quick brown fox -> 빠른 갈색 여우 # jumps over -> 이상 점프 # the lazy dog -> 게으른 개 ``` >

Summary

Roughly, I introduced the Python package "googletrans" that can use Google Translate. As a feature

Is it like this? that's all.

Recommended Posts

I tried using Google Translate from Python and it was just too easy
I tried using UnityCloudBuild API from Python
I tried using pyenv, which I hated without eating, and it was too convenient to sit down.
I tried updating Google Calendar with CSV appointments using Python and Google APIs
I tried web scraping using python and selenium
I tried object detection using Python and OpenCV
I tried using google test and CMake in C
I tried to access Google Spread Sheets using Python
[Python] I tried using OpenPose
I tried using the Python library from Ruby with PyCall
I tried follow management with Twitter API and Python (easy)
[Python] I installed the game from pip and played it
[Python scraping] I tried google search top10 using Beautifulsoup & selenium
I made a server with Python socket and ssl and tried to access it from a browser
I want to copy an English paper from pdf and put it in Google Translate
[Python3] Google translate google translate without using api
Forcibly use Google Translate from python
I tried using Thonny (Python / IDE)
[Python] I tried using YOLO v3
I tried using docomo speech recognition API and Google Speech API in Java
From Python to using MeCab (and CaboCha)
I tried using Twitter api and Line api
Wrangle x Python book I tried it [2]
When I tried to run Python, it was skipped to the Microsoft Store
I tried using PyEZ and JSNAPy. Part 2: I tried using PyEZ
I tried using Bayesian Optimization in Python
[ML-Aents] I tried machine learning using Unity and Python TensorFlow (v0.11β compatible)
Use Python from Java with Jython. I was also addicted to it.
Wrangle x Python book I tried it [1]
I was surprised when I sent Facerank from iPad via udp and relayed, received, and displayed it in Python!
I tried using Headless Chrome from Selenium
I tried to create a sample to access Salesforce using Python and Bottle
[Zaif] I tried to make it easy to trade virtual currencies with Python
I tried to deliver mail from Node.js and Python using the mail delivery service (SendGrid) of IBM Cloud!
I read "Quantum Computer Accelerates Artificial Intelligence" and tried to outline it in Python without using mathematical formulas.
I tried it with SymPy Live, Wolfram Alpha and google with reference to "Algorithm learned with Python 4th: Prime numbers".
python Binary search It is surprisingly easy to implement bisect.bisect_left and bisect.bisect_right from 0
Python programming: I tried to get (crawling) news articles using Selenium and BeautifulSoup4.
Three things I was addicted to when using Python and MySQL with Docker
[Python] None I made nullutil.py because it was cluttered by checking and branching.
I tried to execute Python code from .Net using Pythonnet (Hallo World edition)
I tried using PyEZ and JSNAPy. Part 1: Overview
Csv output from Google search with [Python]! 【Easy】
[Python] I introduced Word2Vec and played with it.
vprof --I tried using the profiler for Python
I want to email from Gmail using Python.
I tried Python! ] I graduated today from "What is Python! Python!"!
I tried using the Google Cloud Vision API
I tried Jacobian and partial differential with python
I tried using mecab with python2.7, ruby2.3, php7
I tried debugging from Python via System Console
I tried function synthesis and curry with python
I tried reading a CSV file using Python
I tried using the Datetime module by Python
A story that was convenient when I tried using the python ip address module
Image processing with Python (I tried binarizing it into a mosaic art of 0 and 1)
I tried pipenv and asdf for Python version control
I tried using TradeWave (BitCoin system trading in Python)
2017-04-11 Python> I tried generator> I was taught generator expression / generator function / next ()
I tried running python etc. from a bat file
Easy way to scrape with python using Google Colab