Skip to main content

stranslate

testspythonCode style: blackLicense: MITPyPI version

Google translate free and unlimited access, stranslate because gtranslate is taken

Install it

pip install itranslate

# or pip install git+https://github.com/ffreemt/google-itranslate
# or use poetry
# poetry add itranslate
# poetry add git+https://github.com/ffreemt/google-itranslate

# to upgrade:
pip install itranslate -U

# or poetry add itranslate@latest

Use it

The quality from this service is not as good as web google translate. There is nothing we can do about it.

It's unclear whether your ip will be blocked if you relentlessly use the service. Please feedback should you find out any information.

from itranslate import itranslate as itrans

itrans("test this and that")  # '测试这一点'

# new lines are preserved, tabs are not
itrans("test this \n\nand test that \t and so on")
# '测试这一点\n\n并测试这一点等等'

itrans("test this and that", to_lang="de")  # 'Testen Sie das und das'
itrans("test this and that", to_lang="ja")  # 'これとそれをテストします'

For those who cannot access google translate, a temporary solution has been implemented. Set cf (it stands for cloudflare) to True, e.g.,

itrans("test this and that", to_lang="de", cf=True) 

Text longer than 5000 characters will be trimmed to 5000. Hence for a long document, you may try something like the following or similar.

from textwrap import wrap
from itranslate import itranslate as itrans

long_doc = """ long long text formatted with \n and so on"""
tr_doc = " ".join([itrans(elm) for elm in wrap(long_doc,
    width=5000,
    break_long_words=False,
    break_on_hyphens=False,
    drop_whitespace=False,
    replace_whitespace=False,
)])

async version: atranslate

If you feel so inclined, you may use the async version of itranslate atranslate:

import asyncio
from itranslate import atranslate as atrans

texts = ["test this", "test that"]
coros = [atrans(elm) for elm in texts]

loop = asyncio.get_event_loop()

trtexts = loop.run_until_complete(asyncio.gather(*coros))

print(trtexts)
# ['测试这一点', '测试']

Proxy support

itrans("test this and that", proxies="http://localhost:8030")

or

proxies = {
    "http": "http://localhost:8030",
    "https": "http://localhost:8031",
}
itrans("test this and that\n another test", proxies=proxies)

itranslate uses httpx to fetch contents and inherits httpx's proxy mechanism. Check https://www.python-httpx.org/advanced/ for other ways of setting up proxies.

Other google translate related repos

Much more sophisticated than itranslate

Disclaimer

google-stranslate makes use of a translate interface floating around the net and is for study and research purpose only. The interface may become invalid without notice, which would of course render the package totally unusable.

Metadata

Release files for itranslate 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for itranslate 0.1.2
File Size Uploaded
itranslate-0.1.2.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for itranslate 0.1.2
File Interpreter ABI Platform
itranslate-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 15.3 kB

Release files / itranslate-0.1.2.tar.gz

Download URL itranslate-0.1.2.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ad294ec12144dbd08cb3577cce23ed8f837a36b305fc83777401881f4a9845dd
BLAKE2b-256 checksum
How to use checksums
5b622255106f8f39059f27155fe10c3c5bcec7f3633b3d4e54125141118ce17e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.1 CPython/3.8.10 Windows/10

Release files / itranslate-0.1.2-py3-none-any.whl

Download URL itranslate-0.1.2-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
efa5d7255d5b06ccfb599f71d2f8db53a496cc28038d41a0fd362a298b674bba
BLAKE2b-256 checksum
How to use checksums
82abc46b50d4e8668cf26c62c694dede39a956b207bbf8f73e5e335fd31c5715
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.1 CPython/3.8.10 Windows/10

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page