If you've ever tried to integrate text translation into your pet project or parser, you know the pain. Official Google Cloud Translation requires card binding and quotas, DeepL API is great but expensive (and complicated to pay from Russia), and writing your own scraper for the web interface of a translator is guaranteed hell with token generation (tk), request signing, and constant layout failures.
But there is translators — a library that does this work for you.
It's an aggregator that (essentially via reverse engineering) accesses the web interfaces of over 30 translation services.
What's under the hood:
1️⃣ Assortment. Besides the usual Google/Bing/Yandex, there is DeepL (best quality for European languages), Baidu/Alibaba (for Chinese), and even specific things like VolcEngine.
2️⃣ HTML-friendly. The
translate_html function can translate content without breaking the tag structure.3️⃣ Smart bypass. Support for different HTTP clients:
requests, httpx, niquests, and even cloudscraper. If one method is blocked by fingerprint, you can switch to another directly in the arguments.4️⃣ JS magic. The library itself executes the necessary JavaScript (via
exejs) to generate request signatures. Yes, Node.js must be installed on the system, but that's a small price for freebies.🧑💻 How it looks in code:
import translators as ts
text = "Python is a language for rebels."
# Use Alibaba engine
print(ts.translate_text(text, translator='alibaba', to_language='ru'))
# Output: Python - это язык для повстанцев.
# Or DeepL (if IP is not banned)
print(ts.translate_text(text, translator='deepl', to_language='ru'))⚠️ Spoonful of tar (inevitable):
This is not a solution for high-load production. It's scraping.
You will get IP-banned if you start hammering thousands of requests per second (though the library has session caching
preaccelerate).Web interface APIs can change without notice, and you'll have to wait for a package update.
But for data analytics, dataset collection, bots, or personal tools — it's a good tool that saves a lot of money.
#good_opensource
Comments
0No comments yet.
Sign in to join the discussion.