A little python to parse Google Translate webpages
Project description
pyGoogleTranslate
A python module for Google Translate (without using the API)
This module lets you get two things:
- translate(text, destination_language, source_language)
Translates the given text into the chosen language.
text: The text to translate
destination_language: The language code (two letters) of the language you want to get.
source_language (default: auto): The language code (two letters) of the language the text is in. ('auto' detects automatically the language the text is in)
- detect_language(text, result_language)
Gives the language of the given text.
text: The text to check.
result_language: The language code (two letters) of the output language.
Installation
You can install pyGoogleTranslate via PIP
the Python Package Index Manager.
pip install pyGoogleTranslate
But you also need to install a compatible browser:
Browser | browser() command | Installation | Notes |
---|---|---|---|
PhantomJS | pyGoogleTranslate.browser('phantomjs') |
On macOS with Homebrew brew cask install phantomjs |
PhantomJS is not maintained anymore but is the most lightweight of all three. ⚠️It seems to not handle Japanese Characters well when rendering. |
Firefox | pyGoogleTranslate.browser('firefox') |
Install Firefox (with the name Firefox) and install the driver (on macOS with Homebrew brew install geckodriver ) |
I tested pyGoogleTranslate on Firefox and it seems to be quite long to start but works well with Japanese Characters which seemed to not work with PhantomJS |
Chrome | pyGoogleTranslate.browser('chrome') |
Install Google Chrome and install the driver (on macOS with Homebrew brew cask install chromedriver ) |
Same as Firefox. |
Usage
import pyGoogleTranslate
>>> pyGoogleTranslate.browser('<browser you want to use>')
>>> pyGoogleTranslate.translate('Hello', 'ja')
'こんにちは'
>>> pyGoogleTranslate.translate('Bonjour', source_language='fr', destination_language='en')
'Hello'
>>> pyGoogleTranslate.detect_language('Hola')
'Spanish'
>>> pyGoogleTranslate.detect_language('Hola', 'es')
'español'
>>> pyGoogleTranslate.detect_language('Nihao')
'Chinese'
>>> pyGoogleTranslate.detect_language('このPythonモジュールをダウンロード頂き誠にありがとうございました。')
'Japanese'
Dependencies
This module has one python module dependency: Selenium, used to automate browsers which is downloaded when installing python-google-translate with PIP.
Google Translate belongs to Google LLC, fully owned by Alphabet Inc.
© Anime no Sekai - 2020
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyGoogleTranslate-2.0.tar.gz
(4.0 kB
view hashes)
Built Distribution
Close
Hashes for pyGoogleTranslate-2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b4079d973716303adaa69012539591518a2ad5b4884851ef59d2b7271032b4d |
|
MD5 | 9f4a6dee42fdc6a3c836d3e6c89bdcf2 |
|
BLAKE2b-256 | c2d22cba40c007420a02111632062ab0d52eec98a1520c2f2cb3c44d638285f3 |