🦀 rtranslate
A simple, dependency-free Rust wrapper for the Google Translate public web API — built using only the Rust standard library.
✨ Features
- 🔹 No external dependencies — uses
std::process::Commandwithcurl. - 🔹 Supports single and batch translations.
- 🔹 Automatically detects the source language (
sl=auto). - 🔹 Graceful error handling for empty responses or rate limits.
- 🔹 Ready to use as a library or CLI example.
📦 Installation
Option 1 — Use directly from GitHub
Option 2 — Clone manually
🧰 Usage
Single translation
use translate;
Output:
Translated: Xin chào thế giới
Batch translation
use translate_vec;
Example output:
Good morning → Chào buổi sáng
How are you? → Bạn khỏe không?
Rust is amazing! → Rust thật tuyệt vời!
🧪 Tests
You can run all unit and integration tests via:
This will:
- Validate URL encoding and parsing
- Check translation parsing logic
- Optionally perform real translation requests (requires internet)
▶️ Examples
Run the included usage example:
examples/basic.rs:
use ;
⚠️ Notes
- This library uses Google’s unofficial translate endpoint (
translate.googleapis.com/translate_a/single). - There are no API keys required, but Google may rate-limit you for frequent requests.
- Recommended for small translation workloads, CLI tools, or quick utilities.
🪪 License
MIT License © 2025 Tien Dat (ntdat104)
💡 Contributing
Pull requests are welcome!
Feel free to:
- Add new language tests
- Improve JSON parsing
- Add async support (with
hyperorreqwest)
🌍 Example Result (EN → VI)
| Input | Output |
|---|---|
| Hello world | Xin chào thế giới |
| How are you? | Bạn khỏe không? |
| Rust is great! | Rust thật tuyệt vời! |
rtranslate — lightweight, offline-friendly, and open to everyone. 🦀